views:

512

answers:

3

If an ASP.NET MVC application using Data Annotations...

<%= Html.ValidationSummary("Things broke...") %>
<% Html.EnableClientValidation(); %>

And we post to the server. Won't we still hit the action, check the ModelState.IsValid and come back to the original view with the validation error. Is it still considered client side validation if we're hitting the server (via a post)?

+1  A: 

Yes, that would be server side validation. If you do the validation on the client side and avoid the form to be posted when any of the fields are invalid, then it's client side validation.

çağdaş
+1  A: 

No, what you just said is not considered client side validation.

Client side validation is considered anything that validates the form in the browser (client), usually with JavaScript. Once the post is sent to the server (ASP.net), then you are in server side validation mode.

I believe what you are really asking though is whether the new asp.net mvc 2.0 validation is client side or not.

EnableClientValidation enables your data annotated models to use the jquery validate plugin to do true client side validating. It should not be posting back to the server to do the validating, but when it does post back it will probably validate on the server as well since client side validation is not 100% reliable.

Greg Roberts
A: 

If you add these libraries it will take care of the client validation.

<script type="text/javascript" src="MicrosoftAjax.js"></script>
<script type="text/javascript" src="MicrosofMVCValidation.js"></script>

These libraries will generate the javascript code for validation. But for this you need to use Dataannotations

Here is an example about it

Barbaros Alp