我有一个(webgrid)它有一个带有(Html.ActionLink)的删除字段,现在我想要返回id值(linkDelete变量)给控制器,但它有错误。
查看:
<div id="tblGrid">
@using (Html.BeginForm())
{
@wb.GetHtml(tableStyle: "gTable", columns:
wb.Columns(wb.Column("کد", format: (item) => item.GetSelectLink(item.Id.ToString())),
wb.Column("Date", "تاریخ"),
wb.Column("Name", "نام"),
wb.Column("Email", "ایمیل"),
wb.Column("Tel", "تلفن"),
wb.Column("Status", "وضعیت بررسی"),
wb.Column(header: "ویرایش", format: (item) =>
{
var linkEdit = Html.ActionLink("تغییر", "Edit", new { ID = item.ID });
return linkEdit;
}),
wb.Column(header: "حذف", format: (item) =>
{
var linkDelete = Html.ActionLink("امحاء", "Delete", new { ID = item.ID });
return linkDelete;
})
)
)
}
控制器:
public ActionResult Delete(int linkDelete)
{
var m = db.Contacts.First(j => j.ID == linkDelete);
db.Contacts.DeleteOnSubmit(m);
db.SubmitChanges();
return RedirectToAction("Index");
}
答案 0 :(得分:0)
您的删除方法参数名称为linkDelete
。但是当您使用Html.ActionLink构建链接时,您正在传递名为ID
的参数!
更改它以匹配您的方法签名。
Html.ActionLink("امحاء", "Delete", new { linkDelete = item.ID });