Can I use an Html helper to render hyperlink with images?
Something like this
<a id="a1" runat="server" href="~/">
<img id="logo" runat="server" src="/_assets/images/logo.png" alt="" />
</a&开发者_StackOverflow中文版gt;
Thanks!
you could easily build your own helper, something like :
public static MvcHtmlString ImgLink(this HtmlHelper htmlHelper, string name, string href, string src)
{
TagBuilder a = new TagBuilder("a");
a.MergeAttribute("name", name);
a.GenerateId(name);
a.MergeAttribute("href", href");
TagBuilder img = new TagBuilder("img");
img.MergeAttribute("src", src);
a.SetInnerHtml(img.ToString(TagRendreMode.SelfClosing));
return MvcHtmlString.Create(a.ToString());
}
and use it like this:
Html.ImgLink("logo", "~/", "/_assets/images/logo.png");
this is not tested, feel free to customize it the way your want/need...
精彩评论