Validate for js with for each

3

In this screen I need to do a validation so that in each record, when the registry is allowed, in case it is marked, bring me the registry that is marked every time I edit (check or uncheck the checkbox).

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

For each functionality, ie (keep material, request material, send reports and request material) make a validation for each action in the case (see screen, search, register, edit, activate / 24 validations. Am I correct?

I wanted an example of how I could do this to the best of my ability. I've already tried but I did not find anything specific to solve my problem. I'm doing a C # project in MVC.

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

    
asked by anonymous 26.11.2015 / 15:29

1 answer

3

Well, since you have no code started, I'll suggest one.

Validations are usually noted in Model . These can be by attributes or by implementing IValidatableObject . An example of attribute validation 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 attribute validation .

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 .

Once you've done this, in View just add the jQuery Validation reference GridView is now ready to use validation.

    
26.11.2015 / 15:50