Reputation: 4854
I am generating data validation javascript in an Asp.Net MVC 3 application with the following code
[DisplayName("Latitude Degrees")]
[Range(0, 90, ErrorMessage = "Latitude degrees must be between {1} and {2}")]
public Int32? LatitudeDegrees { get; set; }
on a view model. When it was MVC2 this worked just fine, if I entered a value outside of 0-90 in the textbox I got the validation warnings.
Since I moved the application to MVC 3, whenever I put any value into the texbox, legal or illegal I get the validation error appear next to it.
I have EnableClientValidation set to true and UseUnobtrusiveJavascript is off (nothing in web.config or the views to turn it on).
Upvotes: 2
Views: 7131
Reputation: 3854
I coudln't reproduce your problem! I'm using ASP.NET MVC3 with ClientValidationEnabled set to true and UnobtrusiveJavaScriptEnabled set to false, and I've tried the same attributes (copy-pasted them, actually), and everything seems to work just as expected. The problem might be somewhere else other than what you've listed here.
Upvotes: 2
Reputation: 1038720
If you want unobtrusive client side validation in web config try setting both ClientValidationEnabled
and UnobtrusiveJavaScriptEnabled
to true. Then make sure you have removed all traces of MicrosoftAjax*
client script libraries and have included jquery and jquery.validate as that's what MVC 3 uses:
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"> </script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
Upvotes: 3