我有以下型号:
public class FormularModel
{
[Required]
public string Position { get; set; }
[Required]
[DataType(DataType.EmailAddress)]
public string Email { get; set; }
[Required]
public string Webcode { get; set; }
}
所需的验证工作正常。但是当我尝试使用 DataType 时它没有反应。
这是我的电子邮件控件的剃刀代码:
@Html.TextBoxFor
(model => model.Email,
new { @style = "width: 175px;", @class = "txtField" }
) *
那么,有人知道答案吗?
TIA
DataType
属性用于格式化目的,而不是用于验证。
我建议你使用ASP.NET MVC 3 未来 http://aspnet.codeplex.com/releases/view/58781用于电子邮件验证。
示例代码:
[Required]
[DataType(DataType.EmailAddress)]
[EmailAddress]
public string Email { get; set; }
如果你碰巧正在使用.NET Framework 4.5
,现在有一个内置的EmailAddressAttribute
住在System.ComponentModel.DataAnnotations.EmailAddressAttribute http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.emailaddressattribute.aspx.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)