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 type of check has been 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 decimal string to string, it will not complain. What's happening?

Edit

I think the annotation is [Number(ErrorMessage = "Message")] because of this. I use this library Data Annotation Extensions

It doesn't seem like I'm using decimal numbers. Does anyone know why?

+6
source share
3 answers

If you use the decimal type, you do not need to use the [Numeric] attribute, because MVC already sees that you are using the numeric type and enter it for you (which causes an error). When you change the line, then you need to specify [Numeric] to tell how you want this line to work.

In the next version of DataAnnotationsExtensions, I will change the [Numeric] attribute so that it does not collide with the MVC version in this case. But for now, removing the [Numeric] attribute will be fine, because [Numeric] for a numeric type is redundant anyway.

+9
source

You probably have several model validators that add the same client rule twice, do you use your own validatiOn provider?

+2
source

Required will become duplicate, since Mark not NULL. Would I change it as decimal?

0
source

Source: https://habr.com/ru/post/886098/


All Articles