Should I use CSLA with ASP.NET MVC 4 & jQuery Mobile?

Should I use CSLA with ASP.NET MVC 4 & jQuery Mobile?

Old forum URL:

TSF posted on Tuesday, May 08, 2012

I'm beginning to learn ASP.NET MVC and plan to use jQuery Mobile.  I'm trying to decide whether it is worth including CSLA in the mix and would like some input.

The reason I ask the question about the usefulness of CSLA in this scenario is because I plan to include a good bit of async javascript calls to reduce postbacks (as I see in numerious online examples).  My understanding is that CSLA only participates when postbacks occur.  I have read that to do javascript-rich MVC apps is essentially duplicating the logic that would otherwise be in my CSLA objects.  So my question is whether it makes sense to go down the CSLA path for this type of application.  What are the benefits of using CSLA even though I'll be doing a lot of async calls via javascript?  Thanks.

JonnyBee replied on Tuesday, May 08, 2012

Jquery and Microsoft.Mvc.Validation java scripts understands DataAnnotation rules and so does the CSLA rule engine.

So you could use DataAnnotation rules for input format rules and do more advanced CSLA rules in the post back. 

As to the new WEB.API I have not looked into that yet. 

The benfit would be to work in a known environment and use CSLA objects for the Model. 

xAvailx replied on Sunday, June 03, 2012

Regardless if you do validation on the client side, you will always have to do the same validation on the server side whether it is w/ CSLA or EF or whatever else you would do on the server. You can never trust that is sent from the client is valid. It is true, you may be able to avoid duplication for some of the simple field validation like required, data types etc... if you use CSLA as your form model, or if you use another common practice like using View/Form Models for your views, but that will only work for the simplest of validations on the client side. When you start doing heavy / rich client JS, the default MVC Jquery validator kind of falls apart (anything to do w/ dynamic loading and adding of input elements requires a heavy dose of coding on the client side). I've been down that road, and it was a difficult one when dealing w/ advanced / rich scenarios on the client side.

My current preference for rich client side apps is creating models/viewmodels on the client w/ a client side MVC/MVVM library like backbone or knockout (there are many out there has a good list of js libraries) and then on the server side for your domain models you can use CSLA for its rules/validation engine. I don't really use any of the other features CSLA features other than the validation engine for these types of applications (no use for n-tier, n level undo, etc...). 


Copyright (c) Marimer LLC