Solved

html.actionlink htmlattributes dictionary bug?

Posted on 2011-09-12
4
579 Views
Last Modified: 2013-11-05
I am trying to use the Html.Actionlink overload that takes and IDictionary<String, Object> as the htmlAttributes parameter.To simplify it, look at this example:

@Html.ActionLink("TEST", "Test", new { test = 1 }, new Dictionary<string, object>())

That is outputting the following HTML:

<a Comparer="System.Collections.Generic.GenericEqualityComparer`1[System.String]" Count="0" Keys="System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Object]" Values="System.Collections.Generic.Dictionary`2+ValueCollection[System.String,System.Object]" href="/Controller/Test?test=1">TEST</a>

i.e. it is writing out all the internal properies of the Dictionary object rather than that acual key value pairs within it.

Obviously, I have tried it with actual data in the dictionary too and the same thing happens.

Am i doing something silly, or is that a bug?

Thanks
0
Comment
Question by:ShaunMitchem
  • 3
4 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36521778
0
 

Author Comment

by:ShaunMitchem
ID: 36521846
Thanks, but that relates to the Route Value parameter - my query is about that htmlAttributes which is an IDictionary<String, Object> according to the help file (and Intellisense)
0
 

Accepted Solution

by:
ShaunMitchem earned 0 total points
ID: 36528364
SOmeone on forums.asp.net helped me with this.  

If instead of using an anonymous type for the RouteValueDictionary as i was doing previously and instead use the explicit declaration:

new RouteValueDictionary(new { id = 1 })

then the problem with the HtmlAttributes dictionary goes away.

I guess this must be because the:

ActionLink(HtmlHelper, String, String, Object, Object)

overload was being used and it therefore wasnt seeing the dictionary as a dictionary - i.e. was iterating through the standard object properties instead
0
 

Author Closing Comment

by:ShaunMitchem
ID: 36555743
This is the answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now