Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 扩展MVC万无一失的验证_Regex_Asp.net Mvc_Asp.net Mvc 3_Validation_Asp.net Mvc Validation - Fatal编程技术网

Regex 扩展MVC万无一失的验证

Regex 扩展MVC万无一失的验证,regex,asp.net-mvc,asp.net-mvc-3,validation,asp.net-mvc-validation,Regex,Asp.net Mvc,Asp.net Mvc 3,Validation,Asp.net Mvc Validation,我想在我的MVC 3应用程序中使用 我需要数字验证,也接受N/a或N/a。因此,我决定创建自己的自定义验证属性,如numericalllownaaattribute,并添加jQuery验证自定义采用程序方法 我重温了MVC万无一失,并决定使用它,因为它已经有了其他有用的构建方法。我也想要那些。现在,我如何使用jQuery验证和服务器端编写一个在客户端工作的CustomValidationAttribute 在谷歌上搜索扩展MVC万无一失我没有得到任何 是否有人遇到过扩展或实现这种方法的情况 使用

我想在我的MVC 3应用程序中使用

我需要数字验证,也接受N/a或N/a。因此,我决定创建自己的自定义验证属性,如numericalllownaaattribute,并添加jQuery验证自定义采用程序方法

我重温了MVC万无一失,并决定使用它,因为它已经有了其他有用的构建方法。我也想要那些。现在,我如何使用jQuery验证和服务器端编写一个在客户端工作的CustomValidationAttribute

在谷歌上搜索扩展MVC万无一失我没有得到任何

是否有人遇到过扩展或实现这种方法的情况 使用jQuery验证插件在服务器和客户端进行验证


您可以通过定义一个新属性来扩展万无一失的MVC,该属性继承了OrtentValidationAttribute(或者万无一失中的一个其他属性,但是大陆非常接近赤裸裸)

您将需要定义以下方法覆盖

public override bool IsValid(object value, object dependentValue, object container)
protected override IEnumerable<KeyValuePair<string, object>> GetClientValidationParameters()
public override string ClientTypeName
定义了服务器端验证逻辑后,需要在客户端向jquery unobtrusive validation注册:

jQuery.validator.addMethod("clienttypenameyouemitontheserver", function(value, element, params) {
    // perform your checks here and return true or false
    return true; 
});

var $Unob = $.validator.unobtrusive;
$Unob.adapters.add("clienttypenameyouemitontheserver", ["param1", "param2", "paramZ"], function (options) {
    var value = {
        param1: options.params.param1,
        param2: options.params.param2,
        paramZ: options.params.paramZ
    };
    setValidationValues(options, "clienttypenameyouemitontheserver", value);
});

您还需要使用万无一失的方法注册属性,例如,
静态MyCustomValidationAttribute(){register.attribute(typeof(MyCustomValidationAttribute));}
jQuery.validator.addMethod("clienttypenameyouemitontheserver", function(value, element, params) {
    // perform your checks here and return true or false
    return true; 
});

var $Unob = $.validator.unobtrusive;
$Unob.adapters.add("clienttypenameyouemitontheserver", ["param1", "param2", "paramZ"], function (options) {
    var value = {
        param1: options.params.param1,
        param2: options.params.param2,
        paramZ: options.params.paramZ
    };
    setValidationValues(options, "clienttypenameyouemitontheserver", value);
});