我的表中有一个删除按钮,我正在尝试删除所选的行。
问题是,我总是在post方法中获得一个空ID。
<div>
<table class="table">
<thead>
<tr>
<th>Role Name</th>
<th>Action</th>
</tr>
</thead>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@using (Html.BeginForm("Delete","Role", new { id = item.Id },FormMethod.Post))
{
<div class="form-actions no-color">
<input type="submit" value="Delete" class="btn btn-default" /> |
</div>
}
</td>
</tr>
}
</table>
在我的控制器里
// POST: Jobs/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult Delete(int id)
{
IdentityRole role = _context.Roles.Find(id);
_context.Roles.Remove(role);
_context.SaveChanges();
return RedirectToAction("Index");
}每当我单击该按钮时,id为空。
发布于 2015-07-02 13:20:37
从您的注释中,在<form>标记中生成的html是
action="/Role/Delete/b1bc13ca-a855-48b0-90e2-9e5fc081ac86"这意味着模型的Id属性是Guid类型。将POST方法签名更改为
public ActionResult Delete(Guid id)https://stackoverflow.com/questions/31184932
复制相似问题