0

I have a C# asp.net MVC web application, and I'm using System.ComponentModel.DataAnnotations for form validation.

Here is an example of validation on a password field:

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; 

In my View, the form has:

@using (Html.BeginForm() {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

I'm planning to use JQuery to Submit my form/model.

Example:

$.post("@Url.Action("Update")",values,function(data)
{
    // do stuff;
});

My question is: will the built-in forms validation still occur, even though I am submitting the data with JQuery?

2
  • Why don't you try it? Commented Aug 24, 2013 at 17:04
  • I assume it does. Since the validation is in the C# code, which is the server side. jQuery is client-side code. When you submit the request with jQuery, then the server-side code will be executed. But, as suggested by 'WannaCSharp', just try it out. Commented Aug 24, 2013 at 18:12

1 Answer 1

1

Yes, it will. The validation in asp.net MVC is done as part of Model Binding. So, when you post your form data to the Update Action, the validation is done when the data is being bound to your Model.

You can read more about it here: Validating Model Data in an MVC Application

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

Comments

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.