Solved

html.actionlink htmlattributes dictionary bug?

Posted on 2011-09-12
4
576 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

10 Experts available now in Live!

Get 1:1 Help Now