1

I want to generate table with, for example, 4 columns. In last column i need link to remove user whitch is in that row. When i am using form tag like this:

@foreach (var item in Model.Approvers)
{
<tr>
    <td>@item.FullName</td>
    <td>@item.Email</td>
    <td>@item.AdAccount</td>
    <td>
        <form id="removeApproverRoleForm" action="~/Admin/RemoveRole"     method="post">
            @Html.AntiForgeryToken()
            <input type="text" id="userId" name="userId" value="@item.Id" />
            <input type="text" id="role" name="role" value="Approver" />
            <a href="#" id="removeApprover" class="button">Remove</a>
        </form>
    </td>
</tr>
 }

It passes last value of userId and role to RemoveRole method. It have to be POST method so this whould not work:

@Html.ActionLink(Remove, "RemoveRole", "Admin", new { role = "Approver", userid = item.Id }, new { onclick = "return removeRole();" })

Even if i place form tag above that, the parameters are still visible in the link.

So i need somehow use new { role = "Approver", userid = item.Id } but send it as a POST and hide those values.

Any ideas? Thank you for help!

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

It is a popular problem, so you can find detailed solution here

Short answer is: use <input type="submit">Remove</input> inside the form OR use

@Ajax.ActionLink("Remove, "RemoveRole", "Admin", new { role = "Approver", userid = item.Id }, new AjaxOptions { HttpMethod = "POST" })

to be able to create ActionLink with controlling the method parameter.

Community
  • 1
  • 1
Ivan Yuriev
  • 488
  • 8
  • 14