<td>
<%= Html.ActionLink("Delete", "DeleteUser", new RouteValueDictionary(new {uname=item.UserName}), new { onclick = "return confirm('Are you sure you want to delete this User?');" }) %>
</td>
In Global.asax.cs
routes.MapRoute(
"DeleteUser",
"Account.aspx/DeleteUser/{uname}",
new { controller = "Account", action = "DeleteUser", uname = "" }
);
In ActionContorller.cs
public ActionResult DeleteUser(string uname)
{
//delete user
}
the value of uname in the controller is being passed is empty string(“”).
Try like this:
Then make sure that the generated link is correct:
Also note that using a plain GET verb for an action that modifies the state on the server is not recommended.
Here’s what I would recommend you:
and in the view:
and in a separate javascript file:
You might also consider adding an anti forgery token to protect this action against CSRF attacks.