开发者

Confirmation dialog on an ActionLink using ASP.NET MVC 2

Does anyone kno开发者_运维技巧w how to add a confirmation dialog with an "actionlinkwithimage"?


You can just add a javascript confirm to your ActionLink like:

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

EDIT: Not sure if you need to know how to implement an ActionLink with an image but here is a helper function that can add an image to an 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));
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜