Has anyone experience form validation not working on MVC3?
My model is marked up with the relevant attributes, e.g:
public string MyClass{
[Required]
public string Name{get;set;}
}
The view also as the appropriate markup:
@Html.TextBoxFor(x=>x.Name)
@Html.ValidationMessageFor(x=>x.Name)
However the validation message never displays. I can see from the generated HTML that it has put in the span tags for the validation but they are marked as being valid instead of error. It seems like the validation on the model just isn’t being called. Any reasons why this might happen?
Do you have the necessary validation JavaScript files for the View?
These either need to live in the layout that the View uses (if it uses any) or the View itself. These JavaScript/jQuery files are what controls client-side validation.
Also, in your Action method on POST, is your Model valid (tested by the
ModelState.IsValidboolean property)?