I have a custom html helper:
public static MvcHtmlString MyLink(this HtmlHelper htmlHelper, string linkText, object htmlAttributes)
{
TagBuilder builder = new TagBuilder("a");
builder.SetInnerText(linkText);
builder.AddCssClass("dialogLink");
return new MvcHtmlString(builder.ToString());
}
Sometimes I would like to add some html attributes to this anchor. For example, I would like to add an additional class to this link. I try this:
public static MvcHtmlString MyLink(this HtmlHelper htmlHelper, string linkText, object htmlAttributes)
{
TagBuilder builder = new TagBuilder("a");
builder.SetInnerText(linkText);
builder.AddCssClass("dialogLink");
if (htmlAttributes != null)
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
return new MvcHtmlString(builder.ToString());
}
But it doesn't work because the class already exist (dialoglink).
How can I proceed to be able to add more css to my link with htmlAttributes?
Thanks