views:

52

answers:

1

I'm using tha namespace System.ComponentModel.DataAnnotations in C# 4 to implement my own validation attribute and it looks like this

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public sealed class MyCustomValidator : ValidationAttribute {
    private String Property1 { get; set; }
    private String Property2 { get; set; }

    public ValeTaxiSituacaoRequired(String property1, String property2) {
        Property1 = property1;
        Property2 = property2;
    }

    public override bool IsValid(object value) {
        //validation logic
    }

}

I wanna use this attribute as below

[MyCustomValidator("Name", "Job")]
[MyCustomValidator("Name", "Email")]
[MyCustomValidator("Name", "Job")]
public class Employe {
}

The problem is that just one validation is perfomed. How can I execute all the validations (using asp.net mvc 2)?

A: 

Take a look at FluentValidation. It allows you to separate your validation from the classes being validated so that you can call your validation logic at any time, on the server or the client.

It allows you to add as many rules of any complexity to a class, without cluttering it with attributes.

Daniel Dyson