create ajax actionlink with html elements in the link text

后端 未结 3 1604
小鲜肉
小鲜肉 2020-12-16 02:33

I would like to convert a link to an ajax action link. I can\'t figure out how to display html elements within the link text?

Here is the original link:



        
3条回答
  •  情歌与酒
    2020-12-16 03:20

    over a year late and everything but this is what I use. Hope it helps someone else.

    @Ajax.RawActionLink(string.Format("Click Me"), "ActionResultName", null, new { item.Variable}, new AjaxOptions { HttpMethod = "Post", InsertionMode = InsertionMode.Replace, UpdateTargetId = "taget-div", LoadingElementId = "target-div" }, new { @class = "class" })
    

    Then the helper...

        public static MvcHtmlString RawActionLink(this AjaxHelper ajaxHelper, string linkText, string actionName, string controllerName, object routeValues, AjaxOptions ajaxOptions, object htmlAttributes)
        {
            var repID = Guid.NewGuid().ToString();
            var lnk = ajaxHelper.ActionLink(repID, actionName, controllerName, routeValues, ajaxOptions, htmlAttributes);
            return MvcHtmlString.Create(lnk.ToString().Replace(repID, linkText));
        }  
    

提交回复
热议问题