xVal and MVC RTW

Apr 5, 2009 at 9:15 PM
Hey all,

I am new to ASP.NET MVC and even newer to xVal however I was wondering if xVal can somehow work with the MVC built in validation in a smoother way?

For example a lot of samples show in the view controller calling TryUpdateModel() which returns bool if object is valid. This would be great to tie right into this and set the ModelState errors automatically like TryUpdateModel() does but via xVal.

I am using ADO Entities and trying to implement model based validation via attributes applied via MetaDataType etc.

I would also like to avoid implementing IDataErrorInfo on all my classes from the Entity Framework. Is there any way we can make model based validation much easier to implement?

I'm hoping we can achieve the nirvana of just applying some attributes via the MetaDataType and make the rest smooth. 

I almost had something like this working with PostSharp. I was using PostSharp to try and avoid any reflection as well but then I stumbled apon xVal and thought instead of re-inventing the wheel it would be good to look into xVal.

Also I am new to jquery etc, how do I in xVal define new CSS so the label shows up in red and the textbox border turns red etc? I haven't been able to find any documentation in xVal or jquery validation on CSS classes to define.

Also what if I want onblur validation? How in xVal can I define if I want this behavior?

Any help would be appreciated!
Apr 6, 2009 at 1:49 PM
Synced, a lot of the things you're asking for (e.g., copying modelbinding errors to ModelState, defining rules using attributes instead of IDataErrorInfo, dynamically applying CSS styles to highlight invalid fields) are exactly what xVal already does. Have you seen the tutorials and demo apps I've posted at the following URLs?
Also what if I want onblur validation?
When you use xVal with jQuery validation (see the tutorials/demo apps at the above URLs), it does validate each field when it loses focus (i.e. onblur).

If your questions aren't answered by the blog posts I've mentioned, please let me know and I'll try to clarify further.