Reputation: 85765
I am using asp.net mvc 3 and I keep getting the following error.
Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: number
I have no clue as I have this
@Html.TextBoxFor(x => x.Mark)
// my viewmodel
[Required(ErrorMessage = "Message")]
[Number(ErrorMessage = "Message")]
public decimal Mark { get; set; }
If I change it from a decimal to string it will not complain. What is going on?
Edit
I think it is because of this the [Number(ErrorMessage = "Message")]
annotation. I am using this library Data annotation extensions
It seems not not like that I am using decimals. Anyone know why?
Upvotes: 6
Views: 3356
Reputation: 598
If you are using type decimal, you do not need to use the [Numeric] attribute because MVC already sees you are using a numeric type and injects that in for you (which is causing the error). When you change to a string, the [Numeric] is then needed to tell the validation how you want that string to work.
In the next version of DataAnnotationsExtensions, I'll change the [Numeric] attribute so it won't collide with the MVC version in this case. But for now, removing the [Numeric] attribute will be just fine because [Numeric] on a numeric type is redundant anyway.
Upvotes: 9
Reputation: 37366
You probably have multiple model validators which are adding the same client rule twice, are you using a custom validatiOn provider?
Upvotes: 2
Reputation: 190945
Required
will become duplicate since Mark
is not nullable. I would change it to be decimal?
Upvotes: 0