0

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

[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)

还尝试使用 jquery 设置值:

$("#Phone_Number").blur(function () {
$("#Validate_cart").val = "dummy"
});

使用 jquery 或按模型设置值,但不会触发验证。我使用提琴手检查过,任何时候都没有调用该方法。

方法

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

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

            }
            catch (Exception)
            {
                throw;
            }
        }
4

1 回答 1

0

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

$("form").validate().settings.ignore

这设置为 ":hidden" 以便验证忽略所有隐藏字段。您可以做的是更改分配给忽略的选择器,如下所示。

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

然后它应该触发远程验证

于 2014-02-27T10:23:59.207 回答