Jack
Jack

Reputation: 1

Do I have to use DataAnnotations if I use jQuery Validation?

I use jQuery Validation and some custom properties like maxlength in my Razor View and with the help of these functionality, I am able to prompt and limit the user from leaving a blank field or exceeding max character limit. So, in this case do I have to use [Required], [Range] or some other DataAnnotations in my Entity classes?

Upvotes: 1

Views: 150

Answers (1)

Rowan Freeman
Rowan Freeman

Reputation: 16348

Data annotations allow for a simple way to add validation on both the server side and the client side in a single location in your code.

With your current technique, is validation being performed on the server as well as the client? Remember that, with javascript, you give the client your source code and even allow them to disable it if they choose, which means you can't rely on it for validation.

DataAnnotations are highly recommended unless you have a better/preferred approach.

Upvotes: 1

Related Questions