I just wanted to point out that this is not that the underscore trick only works with data
attributes, it only works with passing HTML attributes in general. This is because it makes sense to change the underscores to hyphens in the HTML context, since underscores are not used in HTML attributes. However, it is perfectly fair for you to have an underlined route parameter, so the structure cannot make any assumptions about your intentions.
If you need to pass route values with a hyphen, you should use RouteValueDictionary
. This is simply a limitation of anonymous objects that cannot be overcome.
<li>@Html.ActionLink("abc", "abc", "abc", new RouteValueDictionary { { "area", "" }, "sap-ie", "Edge" } }, new RouteValueDictionary { { "id", "nav_abc" } })</li>
Unfortunately, there is no ActionLink
overload that accepts both RouteValueDictionary
for routeValues
and an anonymous object for htmlAttributes
, so including one means switching both. You can technically use any implementation of IDictionary
for the htmlAttributes
parameter, so you can only use new Dictionary { { "id", "nav_abc" } }
. It depends on you.
source share