I am using a Html.TextBoxFor helper in an MVC4 project. Our web designer used a custom property of “error-type” for his box that jquery/javascript looks at to determine how an error should be rendered for that textbox.
I tried doing something like:
@Html.TextBoxFor(m => m.SomeValue, new { error-type="blue" });
But C# doesn’t like the property name of “error-type”.
Is there a way to be able to use the custom property when rendering it through Razor?
Use an underscore; the helper will convert attribute names containing underscores to dashes. FYI, I believe this will only work with MVC-3 or later.
An alternate route is to use the overload that accepts an
IDictionary<string, object>of HTML attributes. That will be both forwards and backwards compatible.