I get the following error:
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required
I have no idea why, I have read some stuff about custom validation and ninject, but I don't think it is that.
I am creating a custom account management system where administrators can create/edit users. I'm using the ASP.NET Membership, Role, Profile
. When you create a new application with Internet
ticked it creates all that account stuff. All I tried to do was reuse the RegisterModel
that is provided with that in my AccountManagement
Area
. But then the error started to appear, I don't have any custom validation providers or anything. The error/exception also appears in Account
Views
as well (the ones created by the MVC template).
The error happens on this line of the view:
<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>
My Model is a ViewModel
class with a property:
public RegisterModel User {get;set;}
I have wrote this entire website with no problems in the way I do anything apart from when it came to just reusing RegisterModel
. Since then I have tried creating a completely new Model
called NewUserModel
and referencing that solely in the Area
to no avail.
I use the DependencyResolver
to use Ninject
as my IoC/DI. I can't imagine that to be a problem....
Model:
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; }
}
}
Usually this type of problem occurs if more than one validation rule is applied to a property. Can you check the followings:
This error came about because of having Ninject.MVC3 added from nuget to the project.
It is something to do with how Ninject injects validation or that is the best answer I could find online!
I removed Ninject entirely from my application, then re-added Ninject (the normal one) and everything works fine!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.