【发布时间】:2016-08-30 21:13:48
【问题描述】:
(这是一个简单的电话簿项目)我想删除列表中的一行(笔记本中的联系人),当用户按下删除按钮时,我想显示它的信息并得到用户的确认 这是查看代码
@model Project1.Models.EF_Model.Phone_book
@{
ViewBag.Title = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Product</h4>
<hr />
<dl class="dl-horizontal">
<tr>
<dt>
@Html.DisplayNameFor(model => model.First_Name)
</dt>
<td>
@Html.DisplayFor(model => model.First_Name)
</td>
<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>
</tr>
</dl>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
@Html.ActionLink("Back to List", "Index")
</div>
}
</div>
在我的控制器中,我检查了基础知识并将 id 发送到模型以将其删除
[HttpGet]
public ActionResult Delete(int? _id)
{
return View();
}
#endregion
#region [- Post -]
[HttpPost]
public ActionResult Delete(int _id)
{
if (ModelState.IsValid)
{
Ref_ViewModel = new ViewModel.ViewModel();
Ref_ViewModel.Delete(_id);
}
else
{
ViewBag.Massage = "Choose a Contact";
}
return View();
}
如何在确认视图中显示我选择的数据?
当我按下按钮删除它时 我也收到了这个错误
参数字典包含“Project1.Controllers.HomeController”中方法“System.Web.Mvc.ActionResult Delete(Int32)”的不可为空类型“System.Int32”的参数“_id”的空条目。可选参数必须是引用类型、可空类型或声明为可选参数。 参数名称:参数
当我按下按钮删除它时,我猜它返回空值或者我必须对 routconfig 做一些事情,请帮助我,我正在工作 2 天(你应该知道我)刚开始学习mvc)
【问题讨论】:
标签: c# html razor controller asp.net-mvc-5