Asp.net mvc 4 对mvc4中的隐藏字段应用远程验证

Asp.net mvc 4 对mvc4中的隐藏字段应用远程验证,asp.net-mvc-4,remote-validation,Asp.net Mvc 4,Remote Validation,mvc中隐藏字段的远程验证不会被触发 型号: [Remote("checker", "mycontroller", ErrorMessage = "Valid combination of phone and account number required.", HttpMethod = "Get")] public string Validate_cart { get; set; } @Html.HiddenFor(model => model.Validate_Par

mvc中隐藏字段的远程验证不会被触发 型号:

[Remote("checker", "mycontroller", ErrorMessage = "Valid combination of phone and account number required.", HttpMethod = "Get")]
        public string Validate_cart { get; set; }
@Html.HiddenFor(model => model.Validate_Paris)
$("#Phone_Number").blur(function () {
$("#Validate_cart").val = "dummy"
});
查看:

[Remote("checker", "mycontroller", ErrorMessage = "Valid combination of phone and account number required.", HttpMethod = "Get")]
        public string Validate_cart { get; set; }
@Html.HiddenFor(model => model.Validate_Paris)
$("#Phone_Number").blur(function () {
$("#Validate_cart").val = "dummy"
});
还尝试使用jquery设置值:

[Remote("checker", "mycontroller", ErrorMessage = "Valid combination of phone and account number required.", HttpMethod = "Get")]
        public string Validate_cart { get; set; }
@Html.HiddenFor(model => model.Validate_Paris)
$("#Phone_Number").blur(function () {
$("#Validate_cart").val = "dummy"
});
使用jquery或by model设置值,但不会触发验证。我使用fiddler进行了检查,任何时候都没有调用该方法

方法

 [HttpGet]
        public  bool checker(string Validate_cart )
        {
            try
            {

                bool isValid = //code to hit database to check the record
                return !isValid;               

            }
            catch (Exception)
            {
                throw;
            }
        }

默认情况下,jquery验证会忽略隐藏字段。这是由于以下设置造成的

$("form").validate().settings.ignore
将其设置为“:hidden”,以便验证忽略所有隐藏字段。您可以做的是更改为“忽略”指定的选择器,如下所示

$(function(){
    $("form").validate().settings.ignore = ":hidden:not([id*=Validate_cart])";
});

然后它应该启动远程验证

但它仍然没有启动验证。请使用
检查器更新您的帖子
操作
代码