我想要一个列,我可以使用自定义表单调用删除[HttpPost]
操作。
这是我到目前为止所做的:
@Html.Grid(Model.PagedList).Columns(column =>{
column.For(x => x.Name);
column.For(x => Html.ActionLink("View", "Details", "Users", new { id = x.UserId }, null));
column.For(x => Html.ActionLink("Edit", "EditUser", new { id = x.UserId }));
}).Sort(Model.GridSortOptions)
那么如何添加一个生成代码的列,如:
<form action="post">
<input type="hidden" name="userId" />
<input type="submit" />
</form>
ps。如果这不是正确的删除方式,请告诉我。我还是新人。
答案 0 :(得分:1)
您可以使用自定义列,如下所示:
@(Html.Grid<SomeModelType>(Model.PagedList)
.Columns(columns =>
{
columns.For(x => x.Name);
columns.Custom(
@<text>@Html.ActionLink("View", "Details", "Users", new { id = item.UserId }, null)</text>
);
columns.Custom(
@<text>@Html.ActionLink("Edit", "EditUser", new { id = item.UserId })</text>
);
columns.Custom(
@<text>
@using(Html.BeginForm("DeleteAction"))
{
@Html.Hidden("userId", @item.UserId)
<input type="submit" value="Delete" />
}
</text>
);
})
.Sort(Model.GridSortOptions)
)