1

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 => Html.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.

Shawn Mclean
  • 56,733
  • 95
  • 279
  • 406

1 Answers1

1

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)
)
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928