ASP.Net MVC3具有多个值远程验证 [英] ASP.Net MVC3 remote validation with multiple values

查看:54
本文介绍了ASP.Net MVC3具有多个值远程验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关使用删除验证来验证单个值此MSDN文章会谈....

http://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....

http://msdn.microsoft.com/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具有多个值远程验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆