Sto provando a portare il vecchio helper HTML.Image, che sono sicuro che tutti hanno usato in un punto o nell'altro, e sto avendo problemi. Di seguito compila bene:Helpers per rasoio e HTML
@Html.Image("my-id", "~/Content/my-img.png", "Alt Text")
Ma quando cerco di usarlo in una vista scrive semplicemente:
<img alt="Alt Text" id="my-id" src="/content/my-img.png" />
e non visualizza l'immagine. Qualcuno può aiutare?
Ecco il codice di supporto HTML.Image che sto usando: motore di visualizzazione
public static class ImageHelper
{
public static string Image(this HtmlHelper helper, string id, string url, string alternateText)
{
return Image(helper, id, url, alternateText, null);
}
public static string Image(this HtmlHelper helper, string id, string url, string alternateText, object htmlAttributes)
{
// Instantiate a UrlHelper
var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
// Create tag builder
var builder = new TagBuilder("img");
// Create valid id
builder.GenerateId(id);
// Add attributes
builder.MergeAttribute("src", urlHelper.Content(url));
builder.MergeAttribute("alt", alternateText);
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
// Render tag
var ret = new MvcHtmlString(builder.ToString(TagRenderMode.SelfClosing));
return ret.ToHtmlString();
}
}
uomo eccezionale. Grazie. Lo apprezzo molto. Controllerò la risposta corretta non appena l'overflow dello stack mi consentirà ... dice che devo aspettare. – jsteve81