Click here to Skip to main content
15,921,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
[Required(ErrorMessage = "Enter Height")]
[Range(0,999, ErrorMessage = "Height is too long")]
[RegularExpression(@"^[0-9]+$", ErrorMessage = "Enter Only Numbers")]

public Nullable<int> Height { get; set; }



i am posting in rest client

C#
{
FighterID: 11,
Height:45,
Weight: 200,
Reach: 33,

}

in place of 45 when i pass any string like



XML
<pre lang="cs">{
FighterID: 11,
Height:"ghgh"
Weight: 200,
Reach: 33,

}



its not checcking validation and giving error
CSS
{
Message: "The request is invalid."
ModelState: {
tblFighters.Height: [2]
0:  "Could not convert string to integer: d. Path 'Height', line 8, position 12."
1:  "Enter Height"
-
}-
Posted
Comments
Sinisa Hajnal 19-Aug-15 4:25am    
Not sure about the order of the validations, but you get Enter Height error which implies he first checks if the parameters match. Try changing the order of the attributes so that regex is the first one.

Other then that, google is your friend :)
Daksh7 19-Aug-15 5:28am    
no after changing the order of attribute same problem occurs
Mayank Vashishtha 19-Aug-15 8:00am    
It is saying so because you are trying to pass a string into an integer. If you had a property of "string" type then it would have made sense. otherwise there is no way it will be validated. Cause validation is secondary, parsing is primary action. If this statement is not even able to parse then how can it be validated? So you change the datatype to string.
Daksh7 20-Aug-15 0:15am    
THANKS. yea your right if i make this height column as string then my validation will working correct and then its doesn't matter what value i am gonna pass there.if i pass string then regex validation gives correct message that "enter number"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900