Praveen VR
Praveen VR

Reputation: 1564

how to fire client side and MVC validations together?

I am working in an MVC application. In my app, I have mvc property validations using data annotations. Also I have some client side validations for some fields. I need to fire both validations together while submit button click.

Currently only client side validation firing first and return false. After valid inputs,then mvc validation works.

Please help

Upvotes: 1

Views: 651

Answers (2)

Praveen VR
Praveen VR

Reputation: 1564

I have used client side validation in "Submit" event of form. So Client side validations and server side data annotations working together.

Upvotes: 0

Max Tkachenko
Max Tkachenko

Reputation: 504

Usually client side validation is used to not send bad data to server. In the same time it repeats server side validation. Server side validation reasons:

  • you are not sure that client validation will always cut off unusable data;
  • you are using the same data structures on your web site and via the API (in the API case you do not even have "client" validation)

The main rule of using validation is cutting off bad data, that cannot be used. Summary: use client side validation combining with server side. If data is passed through client validation, call appropriate methods on the server side. In this scenario you can cover most of the cases.

Upvotes: 1

Related Questions