Click here to Skip to main content
15,891,902 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my form there is multiple validation conditions that needs show according the user input.
Example: when id is exists in database the error shows "Id exists" and when it is empty it shows "Id field is required" and unit filed also shows "unit is required" . I like to hide Unit filed error message when Id exists shows.

Thanks in Advance!

What I have tried:

public class IdIsUniqueAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{

string id = value as string;
if (string.IsNullOrEmpty(id))
return null;
var repo = Ioc.Resolve(typeof(IRepository
C#
<BO.Models.Employee>)) as IRepository<BO.Models.Employee>;
            if (repo == null)
                return null;
           
            var result = repo.Where(l => l.Id == id);            

            foreach (var item in result)
            {
                return new ValidationResult("User Already Exists");   
            }                         
            return null;
        }
Posted
Updated 11-Oct-16 8:21am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900