Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unobstructive client validation error

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?

like image 798
chobo2 Avatar asked Apr 17 '11 19:04

chobo2


2 Answers

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.

like image 76
Scott Kirkland Avatar answered Sep 17 '22 23:09

Scott Kirkland


You probably have multiple model validators which are adding the same client rule twice, are you using a custom validatiOn provider?

like image 26
ryudice Avatar answered Sep 20 '22 23:09

ryudice