我想验证Ville
++是Code-postal
独一无二Pays
的。
如果验证未通过,我想将字段标记为无效(通常为红色)。
我已经尝试了第一个实现,如下所示:
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; }
}
但是在我真正更改其中的某些内容之前,不会检查(验证)所有字段。我需要一个解决方案,每次更改 3 个字段中的一个时,所有 3 个字段都经过验证并在需要时标记为红色。
我已经检查了其他 Stackoverflow 帖子,但没有找到解决我的具体问题的方法。
谢谢你的帮助。