Validate by js with for each

Asked

Viewed 128 times

3

inserir a descrição da imagem aqui

On this screen I need to do a validation so that in each record, when the record has permission, in case it is marked bring me the record marked with it every time I edit (mark or deselect the checkbox).

In case the best way I found is using the foreach in javascript and have to validate the cases following example below.

For each functionality, that is (maintain material, request material, send reports and request material) make a validation for each action in the case (view screen, search, register, edit, activate/inactivate and request chargeback) in the case staying 24 validations. I am correct?

I wanted an example of how I could do this in the best possible way. I’ve looked, but I haven’t found anything specific to solve my problem. I’m doing a C# project on MVC.

Each permission is a different identifier and also depends on each chosen profile.

  • You are using Gridview?

  • 1

    Please put your code in View in the question.

  • Right. With the normal table tag.

  • @Gypsy?

  • Just [Edit] the question and put the code used to generate the View.

  • You need all the records where the checkbox, when changed, is checked ? I didn’t get it very well.

  • @I’m sorry I couldn’t find the code...

  • That screen that’s in the body of the question, there’s no code started, that’s it?

  • @Ciganomorrisonmendez It would have how to specify better where I meet, or send as comment even, because it can help other people.

  • @Ciganomorrisonmendez has no code started to validate that. Only the function that when selecting a profile it loads the gridview... only this

  • @devgaspa Yes exactly. I need that when the checkbox is changed to checked or not checked I want it to update my database, in case it is boolean data.

Show 6 more comments

1 answer

3

Well, since there’s no code started, I’ll suggest a.

Validations are usually noted in Model. Can be by attributes or by implementing IValidatableObject. An example of validation by attributes would be:

public class Perfil
{
    [Key]
    public int PerfilId { get; set; }

    [Required] // Required é um atributo que obriga o usuário
               // a preencher o campo em tela.
    public String Nome { get; set; }
}

Here are more examples of validation by attributes.

Already IValidatableObject forces you to implement a method called Validate:

    public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
    {
        // Coloque aqui sua lógica para validação.
        // Cada problema de validação deve devolver um objeto do tipo
        // ValidationResult.
    }

Here I explain better how to use.

Done so, in the View just add the reference to the jQuery Validation that your GridView is already ready to use validation.

Browser other questions tagged

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