我正在進行擴展。htmlAttributes未與我的分機中的標籤生成器合併
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));
}
這行:
if (htmlAttributes != null) builder.MergeAttributes(htmlAttributes);
錯誤:
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.
我曾嘗試:
if (htmlAttributes != null) builder.MergeAttributes((Dictionary<string, string>)htmlAttributes);
和
if (htmlAttributes != null) builder.MergeAttributes((Dictionary<string, object>)htmlAttributes);
我該如何得到這個工作?
這對我來說真的很有幫助 - 我四處尋找這樣的東西。 –