Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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
ASPNET MVC 3不具结构化,客户端验证无法使用占位符jQuery插件_Jquery_Asp.net_Asp.net Mvc_Jquery Plugins_Customvalidator - Fatal编程技术网

ASPNET MVC 3不具结构化,客户端验证无法使用占位符jQuery插件

ASPNET MVC 3不具结构化,客户端验证无法使用占位符jQuery插件,jquery,asp.net,asp.net-mvc,jquery-plugins,customvalidator,Jquery,Asp.net,Asp.net Mvc,Jquery Plugins,Customvalidator,我试图对ASPNET MVC 3项目和占位符jQuery插件使用非结构化验证,如下所示: [StringLength(20)] [OnlyNumbersValidation(ErrorMessage = " ")] [DisplayName("Fax n°")] public string Fax { get; set; } @Html.TextBoxFor(model => model.Fax, new { @class = "txt-input", placeholder = "Eg

我试图对ASPNET MVC 3项目和占位符jQuery插件使用非结构化验证,如下所示:

[StringLength(20)]
[OnlyNumbersValidation(ErrorMessage = " ")]
[DisplayName("Fax n°")]
public string Fax { get; set; }

@Html.TextBoxFor(model => model.Fax, new { @class = "txt-input", placeholder = "Eg. Fax n°", maxlength = 31 })
@Html.ValidationMessageFor(model => model.Fax, "*", new { @class = "redtxt" })


public class OnlyNumbersValidationAttribute : RegularExpressionAttribute, IClientValidatable
{
    public OnlyNumbersValidationAttribute()
        : base(@"^\d+$")
    {
    }

    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
    {
        {
            var errorMessage = FormatErrorMessage(metadata.GetDisplayName());

            yield return new OnlyNumbersValidationRule(errorMessage);
        }
    }

    public class OnlyNumbersValidationRule : ModelClientValidationRule
    {
        public OnlyNumbersValidationRule(string errorMessage)
        {
            ErrorMessage = errorMessage;
            ValidationType = "digits";
        }
    }
}
问题在于MVC 3和占位符插件之间的交互,因为如果我不输入任何值,而占位符显示为文本,例如Fax n°,则认为我输入了无效输入,因为该文本由字母而不仅仅是数字组成

知道怎么修吗


提前谢谢!Guillermo。

修复了一个错误,该错误涉及在html页面中嵌套表单,并将自定义验证器移动到另一个类,从而修复了该问题。 谢谢。

更新插件解决了我的问题