我安装了数据注释MVC3(我使用的是MVC3),找不到我的[EmailAddress]数据注释。我在网上搜索,我不明白为什么它没有引用。
这是我的模型:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
namespace Projectx.Models
{
public class PreSignUpUser
{
[Required]
[EmailAddress]
public string Email { get; set; }
}
}
有人可以帮我吗?
也许试试这个:
[DataType(DataType.EmailAddress)]
代替
[EmailAddress]
您正在寻找的数据注释实际上是[电子邮件]。
[EmailAddress]不是Data Annotations Extensions的一部分。
对我来说,这些答案没有用。我通过添加System.ComponentModel.Annotations
nuget包解决了这个问题,然后添加了引用
using System.ComponentModel.DataAnnotations;
如果你还没有这样做的话。