Jquery validation in mvc fields

Asked

Viewed 648 times

0

I have a View with some fields, I need to do a validation to check if the field is empty when the user click on a button ex: save, I searched some functions in jQuery no more meets what I need to do, someone knows a jQuery function that validates all fields in a view without having to name the ex field:

Nome :{
        required : true
 }

would like an example where the function is generic, where I can use a single time for several fields.

  • I answered this:
 
 > http://answall.com/questions/11483/validaca-de-campos-no-client-em-asp-net-mvc-4/11485#11485

2 answers

2


The jQuery Validate can help you. It is possible to validate a multitude of things very easily. If you have any difficulty leaving an Issue in the repository, I am the maintainer and can help you with more complex questions.

It has simple uses for validation like this:

<input type="text" data-required />

Or:

<input type="text" data-pattern="^\d+$">

1

If you are using ASP . NET MVC you can decorate its properties with [Required(Errormessage = "Campo obrigatório")] that the framework itself said, provided that jquery validity is loaded at the time necessary for validation.

in your view you should put @Html.ValidationMessageFor(e => e.Propriedade) to display the red message.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.