【发布时间】:2016-09-04 07:50:53
【问题描述】:
我的项目是一个简单的电话簿,我想删除我的(家庭控制器)索引中的一个联系人(左图)并将其信息发送到确认页面(右图)我想显示所选联系人的数据
(例如,如果您删除了 gjgj,它的信息会显示在右侧)
这是我的看法
@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>
这是索引代码(左图)
@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>
这是我在视图中使用的模型
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; }
}
这是我的获取和发布代码
[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
我怎样才能在这部分显示我选择的联系人?
【问题讨论】:
标签: c# view asp.net-mvc-5