I have a class as below,
public class MyClass
{
[Required]
public string Name { get; set; }
[Required]
[Range(1, Int64.MaxValue)]
public long Volume{ get; set; }
}
And used the above class in controller action.
[HttpPost]
public void testAction(, MyClass myClass)
{
var state = ModelState.IsValid;
}
Passing the json input for the controller action
Input type 1: {
"Name":"SomeName",
"Volume":12.2
}
No modal validation failure, and the input data mapped Volume property as 12.
Input type 2: {
"Name":"SomeName",
"Volume": "12.2"
}
Model validation error, "Error converting value "12.2" to type 'System.Int64'."
I want the same model validation failure error even input provide as "Volume":12.2
How to achieve this?
Thanks in advance.