Asp.net mvc 5 将Id传递给ActionMethod

Asp.net mvc 5 将Id传递给ActionMethod,asp.net-mvc-5,Asp.net Mvc 5,我的表中有一个删除按钮,我正在尝试删除所选行 问题是我总是在post方法中得到一个空ID <div> <table class="table"> <thead> <tr> <th>Role Name</th> <th>Action</th> </tr> </thead> @f

我的表中有一个删除按钮,我正在尝试删除所选行

问题是我总是在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>

每当我点击按钮时,您的评论中的id都是空的,在
标记中生成的html是空的

action="/Role/Delete/b1bc13ca-a855-48b0-90e2-9e5fc081ac86"
这意味着模型的
Id
属性是typeof
Guid
。将POST方法签名更改为

public ActionResult Delete(Guid id)

向我们展示您的路线?
location.href
是一种获取方式。您不应该试图对
Delete()
方法进行GET调用。在任何情况下,您的方法都会被
[ValidateAntiForgeryToken]
修饰(但您不会传递令牌)。添加一个表单并在其中放置一个提交按钮(包括
@Html.AntiForgeryToken()
@StephenMuecke我编辑了我的代码并添加了表单,但我仍然得到一个空值。您编辑的代码应该可以。您确定
item.Id
有值吗?-检查生成的Html中的
标记我得到的是:
public ActionResult Delete(Guid id)