Using DataAnnotations 4.0

I am using DA 4.0 with an MVC application and have created a custom validator as shown below:

public static ValidationResult NumberOfItems(int numItems, ValidationContext pValidationContext)
{
    if (numItems == 1)
    {
        //Tag as critical error
        //return new ValidationResult... 
    }

    if (numItems > 1 && numItems <= 10)
    {
        //Tag as non critical error
    }

    //Else it successful
    return ValidationResult.Success;
}

I would like to mark the error message as a critical error or not. If this is not a critical error, I would like to access this in my view and change it differently.

So there are two parts:

  • Tag malfunctions as different types in a custom validator
  • Change the default ModelBinder model to identify a critical error.

How should I do it?

+5
source share
1 answer

MVC. , , . ModelState ViewModel.

" ?" " ".;)

+2

All Articles