2013-07-30 101 views
0

我得到以下錯誤:ASP.NET MVC3驗證類型名稱錯誤

Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required 

我不知道爲什麼,我看了一下自定義驗證和ninject一些東西,但我不認爲這是。

我正在創建一個自定義帳戶管理系統,管理員可以在其中創建/編輯用戶。我正在使用ASP.NET Membership, Role, Profile。當你用Internet創建一個新的應用程序時,它會創建所有帳戶的東西。我所要做的只是重複使用在AccountManagementArea中提供的RegisterModel。但是,然後錯誤開始出現,我沒有任何自定義驗證提供程序或任何東西。錯誤/異常也出現在AccountViews(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> 

我的模型是一個ViewModel類的屬性:

public RegisterModel User {get;set;} 

我已經寫了這整個網站用的方式沒有問題除了剛剛重新使用RegisterModel之外,我做了任何事情。從那以後,我嘗試創建一個全新的Model,名爲NewUserModel,並且僅僅在Area中引用這個結果無濟於事。

我使用DependencyResolver來使用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; } 
    } 
} 
+0

你是否多次包括'jquery.validate.unobtrusive.js'? –

+0

RegisterModel是什麼樣的?你可以使用EditorFor而不是TextBoxFor? –

+0

錯誤是例外,還是顯示在控制檯或...? –

回答

0

此錯誤出現,因爲具有Ninject.MVC3從的NuGet添加到項目中。

這與Ninject如何注入驗證有關,或者這是我可以在網上找到的最佳答案!

我完全從我的應用程序中刪除Ninject,然後重新添加Ninject(正常的),一切工作正常!

0

如果一個以上的驗證規則應用於財產通常發生這種類型的問題。 您可以檢查以下內容:

  1. 查找和檢查所有參考NewUserModel如果任何其他自定義驗證器驗證模型。
  2. 檢查你的NewUserModel是繼承/實現
+0

它不使用任何自定義驗證程序,也不是繼承或實現其他任何其他 –