使用ASP.NET MVC 2的ActionLink上的确认对话框

her*_*rsh 3 asp.net-mvc asp.net-mvc-2

有谁知道如何添加一个带有"actionlinkwithimage"的确认对话框?

Kel*_*sey 5

你可以添加一个javascript confirm到你的ActionLink喜欢:

<%=Html.ActionLink(a => a.ID, "Go", new { onclick="return confirm('Are you sure?');" })%
Run Code Online (Sandbox Code Playgroud)

编辑:不确定您是否需要知道如何ActionLink使用图像实现,但这里有一个辅助函数,可以将图像添加到ActionLink:

public static string ActionLinkImage(this HtmlHelper htmlHelper,
    string imagePath, string altText, string actionName,
    RouteValueDictionary routeValues, IDictionary<string, object> htmlAttributes)
{
    string replaceText = "ActionLinkImageReplaceMe";
    string linkHtml = System.Web.Mvc.Html.LinkExtensions.ActionLink(htmlHelper, 
        replaceText, actionName, routeValues,htmlAttributes);
    return linkHtml.Replace(replaceText,
        String.Format("<img src='{0}' alt='{1}'/>", imagePath, altText));
}
Run Code Online (Sandbox Code Playgroud)