I am using ASP.NET MVC along with JQueryMobile in a web app. I want to generate a link:
<a href="/Whatever/Previous" data-role="button" data-icon="arrow-l">Previous</a>
I have a helper extension method that lets me do:
<%= Html.ActionLink<WhateverController>(c => c.Previous(),
"Previous",
new { data-role = "button", data-icon="arrow-l" } ) %>
Except data-role
and data-icon
are not valid as property names in C#. Using @data-role
doesn't work either.
Is there any syntax to work around this? Or am I stuck with creating a more specialized helper that knows the correct attribute names.
You should be able to use IDictionary<string, object>
instead of the anonymous object:
Html.ActionLink<WhateverController>(c => c.Previous(),
"Previous",
new Dictionary<string, object>
{
{ "data-role", "button" },
{ "data-icon", "arrow-l"}
})
In addition to svick's response, we made a neat change in ASP.NET MVC 3 where properties that have an underscore in them will automatically have the underscores converted to dashes.
So, if you have code like this:
<%= Html.ActionLink<WhateverController>(c => c.Previous(),
"Previous",
new { data_role = "button", data_icon="arrow-l") %>
It will render the markup with dashes:
<a href="/Whatever/Previous" data-role="button" data-icon="arrow-l">Previous</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With