Pass Dictionary of routeValues to ActionLink
- by Graham
All,
Getting to grips with ASP.NET MVC. So far, so good, but this one is a little nuts.
I have a view model that contains a dictionary of attributes for a hyperlink, used like this:
menu = model variable
Html.ActionLink(Html.Encode(menu.Name), Html.Encode(menu.Action), Html.Encode(menu.Controller), menu.Attributes, null)
The problem is the position of "menu.Attributes" expects an object in the form:
new { Name = "Fred", Age=24 }
From what I can tell, this anonymous object is actually converted to a dictionary via reflection anyway BUT you can't pass a dictionary to it in the first place!!!
The Html generated for the link simply shows the dictionary type.
How on earth do I get round this? The whole point is that its general and the controller can have set the menu.Attributes previously....