my project is a simple phone book ,i want to delete a contact in my(home controller) index(Left picture) and send its information to confirmation page(right picture) i want show the data of selected contact
(for example if you deleted the gjgj it's info appears on the right side)
here is my view
@model IEnumerable< Project1.Models.EF_Model.Phone_book>
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
@ViewBag.Massage
<div>
<h4>Phone_book</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Id)
</dt>
<dd>
@Html.DisplayFor(model =>model.Id )
</dd>
<dt>
@Html.DisplayNameFor(model => model.First_Name)
</dt>
<dd>
@Html.DisplayFor(model => model.First_Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Last_Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Last_Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Number)
</dt>
<dd>
@Html.DisplayFor(model => model.Number)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Email)
</dt>
<dd>
@Html.DisplayFor(model => model.Email)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Address)
</dt>
<dd>
@Html.DisplayFor(model => model.Address)
</dd>
</dl>
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.Id)
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>
this is the index code(Left Picture)
@model IEnumerable<Project1.Models.EF_Model.Phone_book>
@{
ViewBag.Title = "Index";
}
<br /><br />
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Id)
</th>
<th>
@Html.DisplayNameFor(model => model.First_Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Last_Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Number)
</th>
<th>
@Html.DisplayNameFor(model => model.Email)
</th>
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.First_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Last_Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Number)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
@Html.ActionLink("Details", "Index", new { id = item.Id }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Id })
</td>
</tr>
}
</table>
this is my model which i'm using in my view
public partial class Phone_book
{
public int Id { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string Number { get; set; }
public string Email { get; set; }
public string Address { get; set; }
}
this is my get and post code
[HttpGet]
// [HttpDelete]
public ActionResult Delete(int? _id)
{
Ref_ViewModel = new ViewModel.ViewModel();
var i = Ref_ViewModel.Select(_id);
return View(i);
}
#endregion
#region [- Post -]
[HttpPost]
//[HttpDelete]
public ActionResult Delete(Models.EF_Model.Phone_book _Model)
{
if (ModelState.IsValid)
{
Ref_ViewModel = new ViewModel.ViewModel();
Ref_ViewModel.Delete(_Model.Id);
}
else
{
ViewBag.Massage = "Choose a Contact";
}
return View(_Model);
}
#endregion
how can i do that to show my selected contact in this part?
Use ActionLink as follows to redirect to another page with id say in the Delete view:
@Html.ActionLink("Add To Cart", "ProductDetails", "Product", new { id = item.ProductId }, new { @class = "btn btn-default", alt = "@Model.ProductName" })
Finally grab the the id from url in the controller using the following and get the details in Delete view:
int id = Convert.ToInt32(Url.RequestContext.RouteData.Values["id"]);
Please check the link: http://kristianguevara.net/creating-your-asp-net-mvc-5-application-from-scratch-for-beginners-using-entity-framework-6-and-identity-with-crud-functionalities/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.