Some questions about best practices when using CSLA and MVC
Some questions about best practices when using CSLA and MVCOld forum URL: forums.lhotka.net/forums/t/8429.aspx
j055 posted on Thursday, January 28, 2010Hi
I've been looking at how to neatly implement some of my business objects into
ASP.NET MVC. I was wondering if there's a better solution to this:
I have a Root BO with a couple of child collections and grandchildren. At the moment I have to map the BO objects to some data objects and add the whole thing to the ViewData.Model property. In the view there are various loops and inner loops of properties which attach to Html Helpers as textboxes and dropdowns etc. When the view is posted the controller action receives the root data object as a parameter. The model binder maps all the form data to the data objects including the nested lists of form fields. I then map the populated objects back to the BOs.
The good thing about this approach is that all the standard MVC binding works with no additional code. The bad things are that I have to create a load of data classes to map to the CSLA objects, I can't use the validation part of CSLA directly with the UI and there are probably some other problems with this approach I haven't yet discovered.
If I try to use the CSLA objects directly with the ViewData I have the problem of handing the form fields after a post. It still requires a lot of manual mapping and the children and grandchildren data make it more complicated. I presume the CslaModelBinder in 3.8 can't help me with that?
You can probably tell that I'm a bit new to MVC so there might be some magic ways to make all this work with a couple of lines of code that I haven't discovered yet. I know I can get all this to work, just not very elegantly. So I'd like to appeal to anyone who can suggest some better approaches to getting the best out of CSLA and MVC particularly taking into account my example outlined above.
Copyright (c) Marimer LLC