In an asp.net mvc web app I want to display a custom message for invalid model values. The issue I'm running into is with numeric properties. A user can put a string into a textbox that is bound to a decimal property and click submit. Since the asp.net mvc model binder cannot bind the string value to the decimal property on my object, it simply keeps it's default value of 0.
I have some model validation going on in my model to check for invalid values and return nice messages, but by the time I reach this code, obviously that decimal property is not invalid on my object (since it is 0). I'm trying to figure out a good way to implement this sort of validation. It seems that I need to intercept the form values and do the validation there.
I had been trying to keep all of my validation in the same place, but it seems like this solution will have many Request.Form's strewn throughout my code. Perhaps I should write my own model binder and put this sort of validation there. I'm just looking for some opinions on this. Thanks!