You can use an anonymous object to pass route values:
@Html.ActionLink( "Delete", "Delete", "Listing", new { id = listing.Guid }, new { onclick = "return confirm('Are you sure you want to delete this listing?')" } )
and the corresponding controller action:
public ActionResult Delete(Guid id) { ... }
And yes, itβs a very bad idea to use ActionLinks and GET requests to invoke actions that change the state on the server (for example, delete something). A much better approach is to use the correct HTTP verb for this case - DELETE. But since HTML forms do not universally support this verb, you can either use AJAX or use the POST verb:
@using (Html.BeginForm("Delete", "Listing", new { id = listing.Guid }, FormMethod.Post, new { onsubmit = "return confirm('Are you sure you want to delete this listing?');" })) { @Html.HttpMethodOverride(HttpVerbs.Delete) <button type="submit">Delete</button> }
and the corresponding controller action:
[HttpDelete] public ActionResult Delete(Guid id) { ... }
source share