I would like to validate that Ville
+ Code-postal
+ Pays
are unique.
If validation does not pass, I would like to mark fields as invalid (red as usually).
I already try a first implementation like below:
public class CityEditViewModel
{
public int CityID { get; set; }
[Required, Remote("CityAlreadyExists", "City", AdditionalFields = "CountryID, CityID, PostCode", ErrorMessageResourceName = "CityAlreadyExists", ErrorMessageResourceType = typeof(UserResource))]
[Display(Name = "City", ResourceType = typeof(UserResource))]
public string CityName { get; set; }
[Required, Remote("CityAlreadyExists", "City", AdditionalFields = "CountryID, CityID, CityName", ErrorMessageResourceName = "CityAlreadyExists", ErrorMessageResourceType = typeof(UserResource))]
[Display(Name = "PostCode", ResourceType = typeof(UserResource))]
public string PostCode { get; set; }
[Required, Remote("CityAlreadyExists", "City", AdditionalFields = "CityName, PostCode, CityID", ErrorMessageResourceName = "CityAlreadyExists", ErrorMessageResourceType = typeof(UserResource))]
[Display(Name = "Country", ResourceType = typeof(UserResource))]
public int CountryID { get; set; }
public List<SelectListItem> Countries { get; set; }
}
But all the fields are not checked (validate) until I really change something in it. I need a solution where every time I change one of the 3 fields, the all 3 fields are validated and marked in red if needed.
I already check other Stackoverflow posts but did not found a solution to my specific problem.
Thanks for your help.