Enable client side validation

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

<add key=”ClientValidationEnabled” value=”true”/>
<add key=”UnobtrusiveJavaScriptEnabled” value=”true”/>

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: , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: