Estoy haciendo una extensión.htmlAttributes que no se combinan con el generador de etiquetas en mi extensión
public static MvcHtmlString Image(this HtmlHelper helper, string src, object htmlAttributes = null)
{
TagBuilder builder = new TagBuilder("img");
builder.MergeAttribute("src", src);
if (htmlAttributes != null) builder.MergeAttributes(htmlAttributes);
return MvcHtmlString.Create(builder.ToString(TagRenderMode.SelfClosing));
}
esta línea:
if (htmlAttributes != null) builder.MergeAttributes(htmlAttributes);
errores con:
The type arguments for method 'System.Web.Mvc.TagBuilder.MergeAttributes<TKey,TValue>(System.Collections.Generic.IDictionary<TKey,TValue>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
que he intentado:
if (htmlAttributes != null) builder.MergeAttributes((Dictionary<string, string>)htmlAttributes);
y
if (htmlAttributes != null) builder.MergeAttributes((Dictionary<string, object>)htmlAttributes);
¿Cómo puedo hacer que funcione?
esto fue realmente útil para mí, busqué algo así como esto. –