用确认对话框删除ActionLink

我试图实现一个简单的ActionLink ,它将使用ASP.NET MVC删除logging。 这是我迄今为止:

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

但是,它不显示确认框。 显然我错过了一些东西,或者我错误地build立了链接。 谁能帮忙?

不要将routeValueshtmlAttributes混淆。 你可能想要这个重载 :

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

那些是你通过的路线

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

你正在寻找的重载方法是这样的:

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

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

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

以上代码仅适用于Html.ActionLink。

对于

Ajax.ActionLink

使用下面的代码:

 <%= 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" })%> 

“确认”选项指定javascript确认框。

您还可以通过将消息与消息一起传递来自定义。 在我的情况下使用MVC和剃刀,所以我可以这样做:

 @Html.ActionLink("Delete", "DeleteTag", new { id = t.IDTag }, new { onclick = "return confirm('Do you really want to delete the tag " + @t.Tag + "?')" }) 

与图像和确认删除,这在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> 

尝试这个 :

 <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> 

使用webgrid 你可以在这里find它 ,动作链接可能如下所示。

在这里输入图像说明

  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() ) 

在更新/编辑/删除logging消息框之前的任何点击事件都会提醒用户,如果“确定”继续操作,其他“取消”操作保持不变。 对于这段代码,不需要单独的java脚本代码。 这个对我有用

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

您也可以尝试Html.ActionLink DeleteId