MVC 5获取CheckBox的值使用Ajax.BeginForm在控制器中检查

时间:2017-03-26 02:29:18

标签: asp.net-mvc checkbox asp.net-mvc-5 ajax.beginform

我使用MVC 5并尝试在控制器中检查复选框的值,但到目前为止它始终返回null。

这是我的代码:

在视图中

@using (Ajax.BeginForm("Delete",
                        "User",
                        new AjaxOptions
                        {
                            HttpMethod = "POST",
                            InsertionMode = InsertionMode.Replace,
                            UpdateTargetId = "table",
                            OnSuccess = "Success",
                            OnFailure = "Fail"
                        }))
{
        <a href="@Url.Action("Create", "User")">Add</a>
        <button type="submit">Delete</button>

<div id="table">
    @{Html.RenderPartial("_UserTable", Model);
</div>
}

我的部分视图

<table>
    <thead>
        <tr>
            <th></th>
            <th>Name</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                   <input type="checkbox" namespace="userCheck" value="@Html.DisplayFor(modelItem => item.UserName)"/>
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.UserName)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Email)
                </td>
            </tr>
        }
    </tbody>
</table>

和我的控制器

public ActionResult
           Delete(string[] userCheck)
        {
            for (int ix = 0; ix < userCheck.Length; ix++)
            {
                // do something with userCheck[ix]
            }
            return Index();
        }

我的按钮工作并转到删除操作,但userCheck始终为空。 如何获取多个复选框的值? 感谢

0 个答案:

没有答案