我RangeValidator在我的模型中有一个属性,只允许0到100之间的整数.我有一个部分视图,显示一个表单,通过jQuery UI对话框更新属性.我查看了源代码,可以确认正确生成了数据注释属性.但是,验证无法正常工作.它确实执行某种验证,但它没有使用我设置的范围.值1,10和100不会产生错误.任何其他单个或两个数字值都会产生错误.但是,如果我用零填充,所有小于100的值都可以.
模型:
public class MyModel
{
...
[Required(ErrorMessage = "{0} is required")]
[Range(typeof(int), "0", "100",
ErrorMessage = "{0} can only be between {1} and {2}")]
public int Percentage { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
局部视图:
@model MyApp.Models.Partials.MyModel
<div id="myDialog" class="editModal" title="Update Percentage">
@using (Ajax.BeginForm("UpdatePercentage", "MyController",
new AjaxOptions() { HttpMethod = "Post",
OnSuccess = "onUpdateSuccess" },
new { name = "myForm" }))
{
@Html.ValidationSummary(null, new { style = "width:auto;max-width:22em;
float:left;clear:both;" })
<div style="width:auto;float:left;clear:both;">
<div style="width:10em;float: left;text-align:right;clear:left;">
@Html.Label("Percentage:")
</div> …Run Code Online (Sandbox Code Playgroud) asp.net-mvc jquery-ui asp.net-mvc-validation data-annotations asp.net-mvc-3
jquery 1.9.0中没有live()函数,但jquery.unobtrusive.ajax.js已经使用了这个函数.
我应该使用旧版本的jquery还是其他方式?