C# ASP.NET MVC3验证类型名称错误

C# ASP.NET MVC3验证类型名称错误,c#,jquery,asp.net-mvc-3,unobtrusive-validation,C#,Jquery,Asp.net Mvc 3,Unobtrusive Validation,我得到以下错误: Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required 我不知道为什么,我读过一些关于定制验证和ninject的东西,但我不认为是这样 我正在创建一个自定义帐户管理系统,管理员可以在其中创建/编辑用户。我正在使用ASP.NET成员资格、角色、配置

我得到以下错误:

    Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required
我不知道为什么,我读过一些关于定制验证和ninject的东西,但我不认为是这样

我正在创建一个自定义帐户管理系统,管理员可以在其中创建/编辑用户。我正在使用ASP.NET成员资格、角色、配置文件。当您创建一个勾选了
Internet
的新应用程序时,它会创建所有帐户内容。我所要做的就是重用我的
AccountManagement
区域中提供的
RegisterModel
。但随后错误开始出现,我没有任何自定义验证提供程序或任何东西。错误/异常也出现在
帐户
视图
中(由MVC模板创建的视图)

错误发生在视图的此行上:

<div class="editor-label">
    @Html.LabelFor(model => model.User.UserName)
</div>
<div class="editor-field">
    @Html.TextBoxFor(model => model.User.UserName) <!-- THIS LINE -->
    @Html.ValidationMessageFor(model => model.User.UserName)
</div>
除了重用
RegisterModel
之外,我写这整个网站的方式没有任何问题。从那时起,我尝试创建一个名为
NewUserModel
的全新
Model
,并仅在
区域
中引用该模型,但毫无效果

我使用
dependencysolver
Ninject
用作我的IoC/DI。我无法想象这会是个问题

型号:

namespace MyApplication.Areas.AccountManagement.Models
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;

    public class NewUserModel
    {
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }

        [Required]
        [Display(Name = "First Name")]
        public string FirstName { get; set; }

        [Required]
        [Display(Name = "Last Name")]
        public string LastName { get; set; }

        [Required, RegularExpression(@"[0-9]{8}", ErrorMessage = "Please enter in an 8 digit Intel Worldwide Id")]
        [Display(Name = "WWID")]
        public string WWID { get; set; }

        [Required]
        [DataType(DataType.EmailAddress)]
        [Display(Name = "Email address")]
        public string Email { get; set; }

        [Required]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [System.Web.Mvc.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }
    }
}

如果对一个属性应用了多个验证规则,则通常会发生此类问题。 你能检查一下吗

  • 如果任何其他自定义验证器正在验证该模型,则查找并检查对NewUserModel的所有引用
  • 检查您的NewUserModel继承/实现了什么

  • 出现此错误的原因是将Ninject.MVC3从nuget添加到项目中

    这与Ninject如何注入验证有关,或者这是我在网上能找到的最好答案


    我从应用程序中完全删除了Ninject,然后重新添加了Ninject(正常的一个),一切正常

    您是否多次包含了
    jquery.validate.unobtrusive.js
    ?RegisterModel看起来像什么?您是否可以使用EditorFor而不是TextBoxFor?错误是否为异常,或显示在控制台中,或…?“重复”:@Ic。我不这么认为,我已经检查了
    视图,它只有一个引用。就像我说的,我已经用同样的方法创建了上百次这样的视图!它没有使用任何自定义验证器,也没有继承或实现任何其他验证器
    
    namespace MyApplication.Areas.AccountManagement.Models
    {
        using System;
        using System.Collections.Generic;
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.Web;
    
        public class NewUserModel
        {
            [Required]
            [Display(Name = "User name")]
            public string UserName { get; set; }
    
            [Required]
            [Display(Name = "First Name")]
            public string FirstName { get; set; }
    
            [Required]
            [Display(Name = "Last Name")]
            public string LastName { get; set; }
    
            [Required, RegularExpression(@"[0-9]{8}", ErrorMessage = "Please enter in an 8 digit Intel Worldwide Id")]
            [Display(Name = "WWID")]
            public string WWID { get; set; }
    
            [Required]
            [DataType(DataType.EmailAddress)]
            [Display(Name = "Email address")]
            public string Email { get; set; }
    
            [Required]
            [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public string Password { get; set; }
    
            [DataType(DataType.Password)]
            [Display(Name = "Confirm password")]
            [System.Web.Mvc.Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
            public string ConfirmPassword { get; set; }
        }
    }