Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 DataAnnotationsExtensions error using numeric attribute

I've installed Scott's Kirkland DataAnnotationsExtensions.

In my model I have:

[Numeric]
public double expectedcost { get; set; }

And in my View:

@Html.EditorFor(model => model.expectedcost)

Now, when the page tries to render 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: number

Any ideas why I'm getting the error ?

like image 809
zynaps Avatar asked Dec 07 '22 22:12

zynaps


1 Answers

The quick answer is simply remove the attribute

[Numeric]

The longer explanation is that by design, validation already adds a data-val-number because it's of type double. By adding a Numeric you are duplicating the validation.

this works:

[Numeric]
public string expectedcost { get; set; }

because the variable is of type string and you are adding the Numeric attribute.

Hope this helps

like image 192
mateuscb Avatar answered Jan 10 '23 13:01

mateuscb