Pass Dictionary of routeValues to ActionLink

Posted by Graham on Stack Overflow See other posts from Stack Overflow or by Graham
Published on 2010-03-13T19:28:32Z Indexed on 2010/03/13 19:35 UTC
Read the original article Hit count: 848

Filed under:
|
|
|

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....

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc