加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 多个字段的远程验证

发布时间:2020-12-16 09:51:39 所属栏目:asp.Net 来源:网络整理
导读:我想验证Ville Code-postal Pays是独一无二的. 如果验证没有通过,我想将字段标记为无效(通常为红色). 我已经尝试过如下的第一个实现: public class CityEditViewModel{ public int CityID { get; set; } [Required,Remote("CityAlreadyExists","City",Addit
我想验证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,CityName",ErrorMessageResourceType = typeof(UserResource))]
    [Display(Name = "PostCode",ResourceType = typeof(UserResource))]
    public string PostCode { get; set; }

    [Required,AdditionalFields = "CityName,PostCode,CityID",ErrorMessageResourceType = typeof(UserResource))]
    [Display(Name = "Country",ResourceType = typeof(UserResource))]
    public int CountryID { get; set; }

    public List<SelectListItem> Countries { get; set; }
}

但是在我真正改变它之前,所有字段都没有被检查(验证).我需要一个解决方案,每当我更改3个字段中的一个时,所有3个字段都会被验证并在需要时标记为红色.

我已经检查过其他Stackoverflow帖子,但没有找到解决我的具体问题的方法.

谢谢你的帮助.

解决方法

我也有类似的情况,这个帮我开始了

$("#FirstName").change(function () {
        $('#CardNumber').removeData('previousValue');
        $('#CardNumber').valid();
  });

Multiple fields validation using Remote Validation

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读