How do I properly validate posted numeric values in asp.net mvc?

Are you examining ModelState. IsValid? It should already be catching this.

Correct, ModelState. IsValid is false. The error message is not very helpful however.

I would like to have a friendlier message such as "You can't put a string in a decimal field, dummy. " It seems that I have to actually get the form value in order to do that sort of validation. – Aaron Palmer Sep 11 '09 at 18:12 No, you don't have to get the value from the form; the user's submitted value is in the ModelStateCollection.As is the specific error.

– Craig Stuntz Sep 11 '09 at 20:32 Ok, ModelStateCollection has ErrorMessage, which is empty, and Exception... which, when drilling down into InnerException a couple times I get something useful. Of course, the most useful message is not the innermost message, or the outermost... sigh – Aaron Palmer Sep 14 '09 at 20:08.

I want to validate textbox1 . Only numeric numbers are allowed. Can enter only numbers between 1 and 30.

How can I do this?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions