有关使用删除验证来验证单个值此MSDN文章会谈....
msdn.microsoft。 COM / EN-US /库/ gg508808%28V = vs.98%29.aspx
在具体地,模型特性归因以便删除验证调用...
公共类CreateUserModel:EditUserModel { [需要] [StringLength(6,MinimumLength = 3)] [远程(IsUID_Available,验证)] [RegularEx pression(@(\\ S)+的ErrorMessage =白色空间是不允许的。) 属性以便发送到操作其他的属性值。 [远程(IsUID_Available,验证,AdditionalFields =电子邮件)]公众覆盖字符串username {搞定;组; },然后你的控制器内的行动:
公众的ActionResult IsUID_Available(用户名字符串,字符串email){ ...}This MSDN article talks about using remove validation to validate a single value....
msdn.microsoft/en-us/library/gg508808%28v=vs.98%29.aspx
In particular, the model properties are attributed so that remove validation is invoked ...
public class CreateUserModel : EditUserModel { [Required] [StringLength(6, MinimumLength = 3)] [Remote("IsUID_Available", "Validation")] [RegularExpression(@"(\S)+", ErrorMessage = "White space is not allowed.")] [Editable(true)] public override string UserName { get; set; } }What I want to achieve is remote validation where a number of fields are taken into account. For example I may want to submit two or three fields in an Ajax manner and get back an overall validation result.
How can this be achieved?
解决方案You could set the AdditionalFields property of the [Remote] attribute in order to have other property values sent to the action.
[Remote("IsUID_Available", "Validation", AdditionalFields = "Email")] public override string UserName { get; set; }and then inside your controller action:
public ActionResult IsUID_Available(string username, string email) { ... }
更多推荐
ASP.Net MVC3具有多个值远程验证
发布评论