Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

html.actionlink htmlattributes dictionary bug?

Posted on 2011-09-12
4
Medium Priority
?
639 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
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

926 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