I'm trying to create a simple custom version of the Html.ActionLink(...) HtmlHelper
I want to append a set of extra attributes to the htmlAttributes annonymous object passed in.
public static MvcHtmlString NoFollowActionLink(this HtmlHelper htmlHelper, string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)
{
var customAttributes = new RouteValueDictionary(htmlAttributes) {{"rel", "nofollow"}};
var link = htmlHelper.ActionLink(linkText, actionName, controllerName, routeValues, customAttributes);
return link;
}
So in my view I would have this:
@Html.NoFollowActionLink("Link Text", "MyAction", "MyController")
Which I'd expect to render out a link like:
<a href="/MyController/MyAction" rel="nofollow">Link Text</a>
But instead I get:
<a href="/MyController/MyAction" values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]" keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" count="1">Link Text</a>
I've tried various methods of converting the annonymous type into a RouteValueDictionary, adding to it then passing that in to the root ActionLink(...) method OR converting to Dictionary, OR using HtmlHelper.AnonymousObjectToHtmlAttributes and doing the same but nothing seems to work.