asp.net-mvcactionlink

Delete ActionLink with confirm dialog


I'm trying to implement a simple ActionLink that will delete records using ASP.NET MVC. This is what I have so far:

<%= Html.ActionLink("Delete", 
                    "Delete", 
                    new { id = item.storyId, 
                          onclick = "return confirm('Are you sure?');" 
                        })%> 

However, it doesn't show the confirm box. Clearly I'm missing something or I have incorrectly built the link. Can anyone help?


Solution

  • Don't confuse routeValues with htmlAttributes. You probably want this overload:

    <%= Html.ActionLink(
        "Delete", 
        "Delete", 
        new { id = item.storyId }, 
        new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) 
    %>