In ASP.NET MVC3 I’m trying to set the css class that the validation error helper method sets. (Not this question, the accepted answer just ADDS the class, I want to override it completely.) In looking at the MVC3 source I’ve found the ValidationInputCssClassName property on the HtmlHelper class. It is settable and it stores the value in a storage provider if set. The get method for the property returns [the provider value] ?? [the default class name].
Now if you just type in HtmlHelper.ValidationInputCssClassName (MSDN entry) in your controller code you’ll see that it is a static readonly field. The reason for this is that there are two HtmlHelper classes, one is in the System.Web.Mvc namespace, and the other is in the System.Web.Webpages.Html namespace. The property System.Web.Webpages.Html.HtmlHelper.ValidationInputCssClassName (MSDN entry) can be set, but it doesn’t seem to have any effect the generated code no matter where I set it.
What am I missing? And what is the difference between these classes?
I’m not positive but I think
System.Web.WebPages.Htmlis for using ASP.net WebForms with Razor.Since
ValidationInputCssClassName, etc. are all readonly fields, I think the only way you are going to get around this is by creating your own HtmlHelper extension methods so you can customize this behavior.From MSDN: