I'm trying to figure out the best way to validate data within a MVC C# app and xVal seemed to be the best fit. However I'm running into a problem with data type validation.
At first I was doing an UpdateModel into the DTO and then running the validation on the DTO. This worked great for things like required fields, however UpdateModel would throw an exception if you tried, for example, to map a string ("asd") into a decimal field. Since UpdateModel had to be ran before there was any data to validate I wasn't sure how to get around that.
My solution was to create a DTO per form that UpdateModel would copy into, run validation on that, and then copy values out into the proper DTOs. All the attributes on the form DTO would be strings so UpdateModel never bombs out, and I'd enforce the data validation through xVal. However while rules like required are kicking in, I can't seem to get the DataType rule to kick in (in this case trying DataType.Currency).
I had also tried getting the client-side validation to work, but I was hoping there was a clean way to do server-side validation of data types.
What have others done with regards to validating data types on the server-side?