0

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)?

3
  • Ok, so why do they call the function EnableClientValidation()? Is it intended to do client validation? Commented Oct 23, 2009 at 13:12
  • The confusing part was why my textboxes were not validating client side. It was because I wasn't using Html.ValidationMessage(textbox) for them or EditorForModel() (which includes the validation message for us in the template)! Commented Nov 2, 2009 at 13:18
  • I prefer using Html.ValidationMessageFor(m => m.FirstName) istead of Html.ValidationMessage('FirstName') to get type safety against the Model - you can also pre-compile your pages to pick up any issues with property names. Commented Jun 20, 2011 at 6:24

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

1

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

1 Comment

I believe that the Html.EnableClientValidation() call adds these to the page on your behalf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.