我的模特有什么问题?无法找到[EmailAddress]命名空间?

问题描述 投票:2回答:3

我安装了数据注释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; }
        }
    }

有人可以帮我吗?

asp.net asp.net-mvc-3 models
3个回答
3
投票

也许试试这个:

[DataType(DataType.EmailAddress)]

代替

[EmailAddress]

1
投票

您正在寻找的数据注释实际上是[电子邮件]。

[EmailAddress]不是Data Annotations Extensions的一部分。


0
投票

对我来说,这些答案没有用。我通过添加System.ComponentModel.Annotations nuget包解决了这个问题,然后添加了引用

using System.ComponentModel.DataAnnotations;

如果你还没有这样做的话。

© www.soinside.com 2019 - 2024. All rights reserved.