Reputation: 36166
Why @Html.TextBoxFor
and other helpers would skip jquery.validation attributes and create elements without those? Am I missing some references or something? It's MVC 3.0 project.
If I add them manually like that:
@Html.TextBoxFor(x => x.Name,
new { data_val="true", data_val_required="Need that field" })
then unobtrusive validation works. But it's suppose build elements and put those attributes based on Model's DataAnnotations
. Model is there, textbox inside of a form body, and still doesn't work. What could it be?
upd: UnobtrusiveJavaScriptEnabled
set to true
in web.config
Upvotes: 0
Views: 214
Reputation: 3191
1.if the text box is loading via ajax, it's may not be parsed for Unobtrusive validation. 2.check rendered html if there is a data-val-required attribute for the text box to determine if it's a server side or client side problem.
Upvotes: 0
Reputation: 7705
For unobtrusive validation to work you need to ensure that UnobtrusiveJavaScriptEnabled
is set to true
in your Web.config
and that you have included these 3 scripts:
Upvotes: 0
Reputation: 39807
Please ensure these two lines in your web.config file
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
Upvotes: 1