I am new to MVC 3 and use the Razor viewer. I use the Html.Hidden extension method to display hidden input element types. What I would also like to do is add a custom attribute to hold the dynamic value. I was impressed with HTML5, we could write custom attributes for the html element that have the prefix "data-". I am trying to do something like below;
@Html.Hidden("hdnID", mymodel.somevalue, new { data-uniqueid = mymodel.somevalue })
in the hope of rendering;
<input type="hidden" value="mymodel.somevalue" data-uniqueid="mymodel.somevalue"/>
The htmlAttributes part (new {data-uniqueid = mymodel.somevalue}) gives an error,
"Invalid member declarator of anonymous type. Members of anonymous type must be declared with member assignment, simple name or member access."
Is it possible to add a user defined attribute to html elements using HtmlHelper classes?
Hi,
source share