Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
Jquery RangeAttribute验证器在客户端的MVC4中未正确验证整数_Jquery_Asp.net Mvc 4_Attributes - Fatal编程技术网

Jquery RangeAttribute验证器在客户端的MVC4中未正确验证整数

Jquery RangeAttribute验证器在客户端的MVC4中未正确验证整数,jquery,asp.net-mvc-4,attributes,Jquery,Asp.net Mvc 4,Attributes,我在模型的一个属性上有以下RangeAttribute验证器: [Range(1, 100, ErrorMessage = "Milestone must be between 1 and 100.")] public int? MilestonePercentage1 { get; set; } 目前,验证器用于标记输入到文本框中的十进制值“.2”。它还将值标记为“0.2” 但是,当我将小数点左边的数字设置为1或更大时: “1.0”或“1.2”等。。。验证器认为这是可以的,并且没有标记它 我

我在模型的一个属性上有以下RangeAttribute验证器:

[Range(1, 100, ErrorMessage = "Milestone must be between 1 and 100.")]
public int? MilestonePercentage1 { get; set; }
目前,验证器用于标记输入到文本框中的十进制值“.2”。它还将值标记为“0.2”

但是,当我将小数点左边的数字设置为1或更大时:

“1.0”或“1.2”等。。。验证器认为这是可以的,并且没有标记它

我在模型中指定int,所以我不知道whey“.2”或“0.9”是无效的,而“1.2”是有效的

我已经使用NUnit编写了一个模型属性测试,它运行正常(.GetAttributesOn是我们编写的扩展方法):

private RangeAttribute;
[设置]
公共图书馆
{
rangeAttribute=new StudyRandomizationCap()
.GetAttributesOn(s=>s.MilestonePercentage1)
第()类
.Single();
}
[遗嘱属性]
public void不包含特定()的任意值
{
Assert.That(rangeAttribute.IsValid(“3.2”),Is.False);
}
但是当我不得不依赖客户端验证程序使用的javascript时,值“3.2”被认为是有效的

我认为在使用客户端脚本(我相信是jquery.validate.js?)时,这个验证器的翻译会丢失一些东西

有什么想法吗?

试试这个:

[Range(typeof(int), 1, 100, ErrorMessage = "Milestone must be between 1 and 100.")]
public int? MilestonePercentage1 { get; set; }

Floremin,这在使用NUnit对其运行测试时确实有效,但在web ui中输入3.2之类的数字时,属性使用的javascript仍然无法正确验证。我开始认为这可能是以下方面的问题:1.RangeAttribute validator 2.jquery-validation.js,或者RangeAttribute如何使用jquery validateion.js.我给你投票支持b/c我还没有尝试在RangeValidator中使用“typeof”。谢谢!
[Range(typeof(int), 1, 100, ErrorMessage = "Milestone must be between 1 and 100.")]
public int? MilestonePercentage1 { get; set; }