ActionLink confirmation dialog using ASP.NET MVC 2

Does anyone know how to add a confirmation dialog with "actionlinkwimimage"?

+3
source share
1 answer

You can simply add javascript confirmto your ActionLinklike:

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

EDIT: Not sure what you need to know how to implement ActionLinkwith an image, but here is a helper function that can add an image to 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));
}
+5
source

Source: https://habr.com/ru/post/1763845/


All Articles