ASP.Net MVC3具有多个值远程验证

编程入门 行业动态 更新时间:2024-10-25 15:36:04
本文介绍了ASP.Net MVC3具有多个值远程验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有关使用删除验证来验证单个值此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具有多个值远程验证

本文发布于:2023-11-14 13:30:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587345.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   ASP   Net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!