首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用确认对话框删除ActionLink

使用确认对话框删除ActionLink
EN

Stack Overflow用户
提问于 2011-01-13 23:57:54
回答 10查看 146.1K关注 0票数 101

我正在尝试实现一个使用ASP.NET MVC删除记录的简单ActionLink。这就是我到目前为止所知道的:

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

但是,它不会显示确认框。很明显,我遗漏了一些东西,或者我错误地构建了链接。有人能帮上忙吗?

EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2011-01-14 00:00:32

不要将routeValueshtmlAttributes混淆。您可能需要this overload

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

Stack Overflow用户

发布于 2011-01-14 00:00:04

这些都是您正在经过的路径

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

票数 15
EN

Stack Overflow用户

发布于 2015-02-12 22:39:15

您还可以通过将delete项与消息一起传递来自定义。在我的例子中,使用MVC和Razor,所以我可以这样做:

@Html.ActionLink("Delete", 
    "DeleteTag", new { id = t.IDTag }, 
    new { onclick = "return confirm('Do you really want to delete the tag " + @t.Tag + "?')" })
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4682107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档