Hi,
I know Im kinda fighting how Asp.Net MVC wants to work, but this is what I'm trying to do. We have a root object, which a child collecion. Editing is done all on the same page.
Normally MVC wants to blow away everything in the collection and recreate it (setting your ids values for you). ideally I'd like to keep the collection intact, and not allow setting of the ids.
I'm trying to keep this Csla business objects as clean as possible, as I want to demo Csla in MVC and Silverlight, using the same classes. I'm trying to get my company to consider Csla so we're not re-inventing the wheel as we continue to build our "domain model."
Andy
It is the stateful vs stateless thing...
MVC defaults to stateless, but you can enable Session and use it. If you do that, you can use the same techniques I used in the Web Forms ProjectTracker PTWeb project to reuse the same business model from a smart client.
You lose some scalability, but it may be worth it to gain the reuse - all depends on the app requirements.
Rocky,
Yes, that part is easier. And we have memcache servers which already hold the little session state we have.
My main confusion lies in the ModelBinder stuff; do I just need a modelbinder which looks for collection items who's Id isn't in the form post and remove, and manually add the new ones?
Andy
I've accomplished this in a few ways...
1-) In controller create/update I fetch object graph from db. Then I model bind only the root using try update model and manually update the child collection.
2-) Create a custom model binder for your object. This moves the complexity of binding from controller into a custom model binder.
Unfortunately the MVC model binder destroys the collection, and likes to re-add / remove items. I've had same issue even when using EF Feature 5 CTP POCOs. In the past I had posted about updating the Csla Model Binder to work better with collections, but don't think any work was done.
http://forums.lhotka.net/forums/p/9419/44655.aspx#44655
http://stackoverflow.com/questions/1242758/what-is-correct-behaviour-of-updatemodel-in-asp-net-mvc
HTH...
@xAvailx, have you looked at the CSLA 4 CslaModelBinder? I think Gary and/or Ricky did some work around collections.
In the context of this particular thread however, there's one other option.
If your controller implements IModelCreator (from Csla.Web.Mvc), the CslaModelBinder will invoke a CreateModel method on the controller when an instance of the model is required. This allows your controller to easily return an appropriate model instance for use by the model binder.
Normally you'd create an instance of the model by using DataPortal.Create, but in this case you could retrieve an existing model from Session.
Hi Rocky,
IIRC I was using 3.8 but using the Model Binder for 4.0. So I believe the problem is still there for 4.x
Thx.
I've accomplished this in a few ways...
1-) In controller create/update I fetch object graph from db. Then I model bind only the root using try update model and manually update the child collection.
2-) Create a custom model binder for your object. This moves the complexity of binding from controller into a custom model binder.
Unfortunately the MVC model binder destroys the collection, and likes to re-add / remove items. I've had same issue even when using EF Feature 5 CTP POCOs. In the past I had posted about updating the Csla Model Binder to work better with collections, but don't think any work was done.
http://forums.lhotka.net/forums/p/9419/44655.aspx#44655
http://stackoverflow.com/questions/1242758/what-is-correct-behaviour-of-updatemodel-in-asp-net-mvc
HTH...
Hi
How can we update the child collection manually, provide me some samples related to child collection. I am getting hanged in my solution where I am using parent and child collection object, I am dynamically adding the child collection in runtime, when I post the object back to the controller, child collection object showing as count=0, it is not binding to the parent object.
fwiw, there are some improvements to collection binding in 4.2.
I think there'll be more yet in 4.3 to support the latest MVC datagrid concepts.
fwiw, there are some improvements to collection binding in 4.2.
I think there'll be more yet in 4.3 to support the latest MVC datagrid concepts.
Where can I get that information? I've purchased CSLA 4 E-book series and currently using the 4.2 version. facing the same problems with the child collection objects and child object in MVC 3. If there are any specific examples in this regard please let me know.
Thanks and Regards
SreeRam.
The ebook uses 4.1. There is no documentation for the (as yet unreleased) 4.2 changes.
Copyright (c) Marimer LLC