以下代码的含义是什么? [英] What is the meaninf of following code?

查看:95
本文介绍了以下代码的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以解释下面的代码吗?





Can anybody explain me the following code??


[Required(ErrorMessage = "The email field is required.")]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.")]
//[DataType(DataType.EmailAddress)]
[RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessage = "Please enter a valid email")]
[Display(Name = "Email")]
public string ContactEmail { get; set; }

推荐答案

,ErrorMessage = 请输入有效的电子邮件)]
[显示(名称= 电子邮件)]
public string ContactEmail { get ; set ;}
", ErrorMessage = "Please enter a valid email")] [Display(Name = "Email")] public string ContactEmail { get; set; }


这些应用于给定属性的4个属性,通常它们在验证的上下文中使用,这里的含义是:

1. 必需 - 根据需要标记属性,如果用户忘记输入此属性的值,将显示相关消息。

2. StringLength - 将字符串的最大长度设置为100,但在这种情况下未正确设置错误消息。请参阅此处的详细信息: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute(V = vs.110) .aspx [ ^ ]

3. RegularExpression 设置将用于验证<$的正则表达式c $ c>用户输入。

4. 显示 - 设置此属性的默认显示名称。这将在生成的Views中的ASP.NET MVC中用作此属性的标签名称。
These are 4 attribuits applied to the given property, and normally they are used in the context of validation, and here are the meaning:
1. Required - mark the property as required, and if the user forgot to enter a value for this property the associated message will be shown.
2. StringLength - set the max length of the string to 100, but the error message is not set correctly in this case. See details here: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.stringlengthattribute(v=vs.110).aspx[^]
3. RegularExpression set the regular expression that will be used to validate the user input.
4. Display - set the default display name for this property. This will be used in ASP.NET MVC in the generated Views as the name of the label for this property.


这篇关于以下代码的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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