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" })
Sourced from Stackoverflow