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);

Как я могу заставить это работать?

7
задан Erik Philips 22 June 2014 в 22:58
поделиться