Sunday, 18 August 2013

Custom validation determine if Create or Update

Custom validation determine if Create or Update

How do I validate only at Create item but not in Update item? Currently
now the code will also validate in Update, I want the validate only apply
in create Item, any idea? I had search through google, and still had no
idea to figure it out, any help will be great
Custom Validation
public class CompanyExistAttribute : ValidationAttribute
{
private Entity db = new Entity();
private Helper hp = new Helper();
protected override ValidationResult IsValid(object value,
ValidationContext validationContext)
{
var result = hp.GetCompanyInfo((string)value).Any();
if (result == true){
return new
ValidationResult(this.FormatErrorMessage(validationContext.DisplayName));
}
return null;
}
}
}
Model
[CompanyExist]
public object CompanyCode;

No comments:

Post a Comment