MVC Contribute Branch For MVC 2 Beta

MVC Contribute Branch For MVC 2 Beta

Old forum URL: forums.lhotka.net/forums/t/8070.aspx


xAvailx posted on Tuesday, December 01, 2009

Hi,

Any plans on maybe creating a branch for MVC 2 Beta for the MVC Contribute project? I am converting some of the code at the moment, but running into ModelBinding problems. I can't get this test to pass:

BindCallsCorrectMethodOnFactoryMethodWithArgument

The problem i have with binding is when using a ViewModel class. If I use BO directly it works fine.

Edit:

The unit test error I receive is:

Error 1 TestCase 'CslaContrib.Mvc.Test.CslaBindModelBinderTest.BindCallsCorrectMethodOnFactoryMethodWithArgument'
failed: System.ArgumentNullException: Value cannot be null.
Parameter name: context
at System.Web.Mvc.AssociatedValidatorProvider.GetValidators(ModelMetadata metadata, ControllerContext context)
at System.Web.Mvc.ModelValidatorProviderCollection.<>c__DisplayClass1.b__0(ModelValidatorProvider provider)
at System.Linq.Enumerable.d__14`2.MoveNext()
at System.Web.Mvc.DefaultModelBinder.OnPropertyValidated(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, Object value)
at System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
at CslaContrib.Mvc.DefaultCslaModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) in D:\Projects\CslaContrib.Mvc\CslaContrib.Mvc\DefaultCslaModelBinder.cs:line 67
at CslaContrib.Mvc.DefaultCslaModelBinder.BindCslaModel(ControllerContext controllerContext, ModelBindingContext bindingContext) in D:\Projects\CslaContrib.Mvc\CslaContrib.Mvc\DefaultCslaModelBinder.cs:line 58
at CslaContrib.Mvc.CslaBindModelBinder.BindCslaModel(ControllerContext controllerContext, ModelBindingContext bindingContext) in D:\Projects\CslaContrib.Mvc\CslaContrib.Mvc\CslaBindModelBinder.cs:line 27
at CslaContrib.Mvc.DefaultCslaModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) in D:\Projects\CslaContrib.Mvc\CslaContrib.Mvc\DefaultCslaModelBinder.cs:line 24
at CslaContrib.Mvc.Test.CslaBindModelBinderTest.BindCallsCorrectMethodOnFactoryMethodWithArgument() in D:\Projects\CslaContrib.Mvc\CslaContrib.Mvc.Test\CslaBindModelBinderTest.cs:line 71 D:\Projects\CslaContrib.Mvc\CslaContrib.Mvc\DefaultCslaModelBinder.cs 67

rasupit replied on Wednesday, December 02, 2009

I don't think the model binder in contrib site will work with MVC 2, the make changes to model binder to support data annotation.

I'm planning to wait a little longer until MVC 2 make several releases before making any upgrade to the mvc contrib project.  From experience with MVC 1, they still make a lot of internal implementation changes up to RC release.

Ricky

xAvailx replied on Wednesday, December 02, 2009

Thanks Ricky.

I had to make some changes to the source because of breaking changes. But I've gotten all the other tests to work, just the one I mentioned above is failing. I will branch out and then can send you a patch if you want. Most of the changes are due to ModelType, and Model properties are now deprecated because of ModelMetaData.

rasupit replied on Wednesday, December 02, 2009

Yes, please do.

I took a cursory look at it and saw the change to ModelMetaData.  Although I'm not sure if that will hold, they may change again later to ModelDescriptor or something and wrap the metadata info in there ;)

There is also the double validation error in modelstate that Rocky have found when you're csla bo uses data annotation attribute.

Ricky

RockfordLhotka replied on Thursday, December 03, 2009

I hope that a future version of the contrib work would take advantage of the CslaModelBinder in Csla.Web.Mvc. In other words, I'd rather have people use the "official" binder in CSLA .NET and tell me if it is insufficient (so I can fix it) than create their own for their projects.

rasupit replied on Thursday, December 03, 2009

Rocky, The initial contrib work was created as experimental only.  That time, I was not aware about your plan on adding anything to support asp.net mvc. 

I do hope you would add the functionality implemented in the contrib project which were showcased on the project tracker sample

I have described some of the issues when binding csla object using the default binder here.  There is also an issue on having csla object in an action method argument.  This is due to the way csla object being instantiate through factory method.

RockfordLhotka replied on Thursday, December 03, 2009

For 4.0 I do plan to expand the basic CslaModelBinder from 3.8 to address the object creation issue – I have a plan for that. I wasn’t aware of the collection issue, so I’ll have to look into that more closely.

 

Do you want to help with the 4.0 implementation? I believe you already have a signed contributor agreement on file.

 

And I’ve also created a Controller base class in 4.0 that provides some protected methods that make it a little easier to work with CSLA model objects in a stateless model. Specifically I noticed that insert/update operations require the same 6-8 lines of code every time (to get exception handling, etc), so I encapsulated that behavior in the base class.

 

rasupit replied on Thursday, December 03, 2009

I would love to help out with 4.0, let me know how the detail. I believe you have my email.  I haven't get a chance to play around with VS2010 though;  Still struggle with upgrading my laptop to win7, since I have to clean install it. 

Yes, I have signed contributor agreement when helping out to improve performance on reflection calls.

xAvailx replied on Friday, December 04, 2009



And I’ve also created a Controller base class in 4.0 that provides some protected methods that make it a little easier to work with CSLA model objects in a stateless model. Specifically I noticed that insert/update operations require the same 6-8 lines of code every time (to get exception handling, etc), so I encapsulated that behavior in the base class.



Is that in SVN somewhere where I can take a peek?

RockfordLhotka replied on Friday, December 04, 2009

Yes, the /core/trunk folder is 4.0 - very unstable (might not even build right now), but my first run at a Controller base class is in svn.

Copyright (c) Marimer LLC