By default client side scripting disabled by default. To enable Client side scripting in MVC you need to follow the below 2 steps.
Step 1:
To Enable Client Side validation in web.config
<appSettings>
<add key=”ClientValidationEnabled” value=”true”/>
<add key=”UnobtrusiveJavaScriptEnabled” value=”true”/>
</appSettings>
Step 2:
– Include reference of javascript files in the masterpage
– Avoid adding reference in each and every View page
Add the following references in Masterpage
<script src=”~/Scripts/jquery-1.8.2.min.js” type=”text/javascript”></script>
<script src=”~/Scripts/jquery.validate.min.js” type=”text/javascript”></script>
<script src=”~/Scripts/jquery.validate.unobtrusive.min.js” type=”text/javascript”></script>
The order of adding reference are also important.
Now we can able to validate in client side by avoiding round trip to server side.
Tagged: Avoid round trip in MVC, Client side validation in MVC, Enable client side validation
Leave a Reply