Implementing a Post in MVContrib Grid for delete purposes
I want a column which I can have a custom form that calls to a delete [HttpPost]
action.
This is what I have so far:
@Html.Grid(Model.PagedList).Columns(column =>{
column.For(x => x.Name);
column.For(x => H开发者_StackOverflow中文版tml.ActionLink("View", "Details", "Users", new { id = x.UserId }, null));
column.For(x => Html.ActionLink("Edit", "EditUser", new { id = x.UserId }));
}).Sort(Model.GridSortOptions)
So how do I add a column that generates code such as:
<form action="post">
<input type="hidden" name="userId" />
<input type="submit" />
</form>
ps. If this is not the correct way of deleting, please tell. I'm still new.
You could use a custom column, like this:
@(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)
)
精彩评论