Remove ActionLink using confirmation dialog

I am trying to implement a simple ActionLink that will delete records using ASP.NET MVC. This is what I still have:

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

However, it does not show a confirmation window. It is clear that I missed something or built the link incorrectly. Can anyone help?

+89
asp.net-mvc actionlink
Jan 13 '11 at 15:57
source share
10 answers

Do not 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?');" }) %> 
+195
Jan 13 '11 at 16:00
source share

these are the routes that you go to

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

The overloaded method you are looking for is the following:

 public static MvcHtmlString ActionLink( this HtmlHelper htmlHelper, string linkText, string actionName, Object routeValues, Object htmlAttributes ) 

http://msdn.microsoft.com/en-us/library/dd492124.aspx

+13
Jan 13 '11 at 16:00
source share
 <%= Html.ActionLink("Delete", "Delete", new { id = item.storyId }, new { onclick = "return confirm('Are you sure you wish to delete this article?');" }) %> 

The above code only works for Html.ActionLink.

For

Ajax.ActionLink

use the following code:

 <%= Ajax.ActionLink(" ", "deleteMeeting", new { id = Model.eventID, subid = subItem.ID, fordate = forDate, forslot = forslot }, new AjaxOptions { Confirm = "Are you sure you wish to delete?", UpdateTargetId = "Appointments", HttpMethod = "Get", InsertionMode = InsertionMode.Replace, LoadingElementId = "div_loading" }, new { @class = "DeleteApointmentsforevent" })%> 

The Confirm option specifies the javascript confirmation flag.

+13
Mar 11 '13 at 8:55
source share

You can also customize by passing a delete item along with the message. In my case using MVC and Razor, so I could do this:

 @Html.ActionLink("Delete", "DeleteTag", new { id = t.IDTag }, new { onclick = "return confirm('Do you really want to delete the tag " + @t.Tag + "?')" }) 
+2
Feb 12 '15 at 2:39
source share

Try the following:

 <button> @Html.ActionLink(" ", "DeletePhoto", "PhotoAndVideo", new { id = item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</button> 
+2
Feb 23 '16 at 12:32
source share

Using webgrid you can find it here , links to actions can look like this.

enter image description here

  grid.Column(header: "Action", format: (item) => new HtmlString( Html.ActionLink(" ", "Details", new { Id = item.Id }, new { @class = "glyphicon glyphicon-info-sign" }).ToString() + " | " + Html.ActionLink(" ", "Edit", new { Id = item.Id }, new { @class = "glyphicon glyphicon-edit" }).ToString() + " | " + Html.ActionLink(" ", "Delete", new { Id = item.Id }, new { onclick = "return confirm('Are you sure you wish to delete this property?');", @class = "glyphicon glyphicon-trash" }).ToString() ) 
+2
Sep 24 '17 at 11:36 on
source share

With image and confirmation of deletion that works on mozilla firefox

 <button> @Html.ActionLink(" ", "action", "controller", new { id = item.Id }, new { @class = "modal-link1", @OnClick = "return confirm('Are you sure you to delete this Record?');" })</button> <style> a.modal-link{ background: URL(../../../../Content/Images/Delete.png) no-repeat center; display: block; height: 15px; width: 15px; } </style> 
+1
Feb 23 '16 at 12:39
source share

enter image description here MVC5 with delete dialog and glyph. Previous versions may work.

 @Html.Raw(HttpUtility.HtmlDecode(@Html.ActionLink(" ", "Action", "Controller", new { id = model.id }, new { @class = "glyphicon glyphicon-trash", @OnClick = "return confirm('Are you sure you to delete this Record?');" }).ToHtmlString())) 
0
Dec 21 '18 at 12:28
source share

Any click before before event for updating / editing / deleting entries warns the user, and if "Ok" goes to action, then "cancel" remains unchanged. There is no need to edit separate java script code for this code. he works for me

<a asp-action="Delete" asp-route-ID="@Item.ArtistID" onclick = "return confirm('Are you sure you wish to remove this Artist?');">Delete</a>

-one
Oct 25 '17 at 7:44
source share

You can also try this for Html.ActionLink DeleteId

-2
Jul 30 '14 at 19:44
source share



All Articles