I\'m trying to port the old HTML.Image helper, that I\'m sure everyone has used at one point or another, and I\'m having issues. The following compiles fine:
I had the same problem and i had used MvcHtmlString as return type for these 2 extension method and it works
public static class ImageHelper
{
public static MvcHtmlString Image(this HtmlHelper helper, string id, string url, string alternateText)
{
return Image(helper, id, url, alternateText, null);
}
public static MvcHtmlString Image(this HtmlHelper helper, string id, string url, string alternateText,
object htmlAttributes)
{
var builder = new TagBuilder("img");
builder.GenerateId(id);
builder.MergeAttribute("alt", alternateText);
builder.MergeAttribute("src",url);
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
}
}