I Create this class.
public class UniqueFileNumber : ValidationAttribute
{
private string _LocationFile;
public override string FormatErrorMessage(string str)
{
return ViewRes.ValidationString.Loc_FileNumberExist;
}
public override bool IsValid(object value)
{
DBEntities _db = EntityFactory.GetEntity();
string strName = Convert.ToString(value);
return !_db.Locations.Any(p => p.LocationFile == strName);
}
}
and add this attribute to my entity Like that.
[UniqueFileNumber]
public object FileNumber{ get; set; }
The validation work only on the PostBack (Refresh).
It would be fine if it's work on client side too. In my client side , I add that line
<% Html.EnableClientValidation(); %>
What's the problem here.
thanks.