MVC Html Extension return string instead of html markup?

后端 未结 2 1872
南笙
南笙 2021-02-12 22:26

If I have en extension like that :

 public static string ImageLink(this HtmlHelper htmlHelper,
                                      string imgSrc, 
                    


        
2条回答
  •  温柔的废话
    2021-02-12 23:09

    Have it return MvcHtmlString instead (my sample below).

     public static MvcHtmlString IconImg(this HtmlHelper htmlHelper, string icon, string title = "", string size = "16x16") {
            string path = VirtualPathUtility.ToAbsolute("~/res/img/icons/" + size + "/" + icon + ".png");
            string imgHtml = "";
            return new MvcHtmlString(imgHtml);
        }
    

提交回复
热议问题