Generate html attributes with dash through C# view engines
How do you generate attributes for html elements that have a dash (-) in them through a C# view template engine while using object initialiser syntax?
Use an underscore (_) instead.
An example. In a Razor view using the Html.ActionLink(...) helper to create an anchor element with an attribute called 'data-values' the code would be:
@Html.ActionLink(
"link text",
"actionName",
new { Model.Id },
new { data_values = "some-value-for-the-data" })
Written by Steven Hunt
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Razor
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#