Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Model State Validation in ASP.NET WEBAPI Core

I am trying to use model validation in ASP.NET WEBAPI Core. Below mentioned is the code from my model.

[Range(typeof(decimal), "1.0", "90.1")]
public decimal price{ get; set; }

My understanding is, if I pass any value which is not in between 1.0 - 90.1, the ModelState.Valid should be false.

Here is the url I tried to call the method,

http://localhost:57270/api/testprice?price=132.7492634

Since the value which I have passed greater than 90, I was expecting ModelState.Valid as false. But always the ModelState.Valid is coming as true.

Am I missing anything? Please help?

like image 647
Ane Avatar asked Sep 11 '26 03:09

Ane


1 Answers

Try this:

[Range(1.0, 90.1)]
public decimal price{ get; set; }
like image 135
Jack Sparrow Avatar answered Sep 12 '26 16:09

Jack Sparrow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!