Hi
I'm trying to use 3.8.3 with MVC 2. Is this supported? I changed the default model binder:
ModelBinders.Binders.DefaultBinder = new Csla.Web.Mvc.CslaModelBinder();
After I call the UpdateModel method:
UpdateModel(order, collection);
I get the following exception:
Method not found: 'System.Collections.Generic.IDictionary`2<System.String,System.Web.Mvc.ValueProviderResult> System.Web.Mvc.ModelBindingContext.get_ValueProvider()'.
Stack Trace:
|
Can you tell me what I'm doing wrong?
Thanks
Andrew
Hello,
Yes, this is supported. Please take a look at this post and this post for more information. If you are still experiencing this issue after reading these two threads, please let us know.
Thanks
-Blake Niemyjski
Hi
I've read the posts but I don't see anything in there that helps me with my problem. I was assuming I could get the model binding to work with just CSLA and CSLA.Web.MVC.
Please advise.
Thanks
Andrew
The CslaModelBinder in 3.8 only directly supports BusinessBase objects. The CSLA 4 CslaModelBinder supports BusinessListBase as well. I suspect this might be the problem you are encountering.
MVC 2 was working its way through pre-release as our development shifted from 3.8 to 4, and so the 3.8 implementation is essentially incomplete - we stopped working on 3.8 before MVC 2 was stable.
However, you should be able to take the CSLA 4 Csla.Web.Mvc project and use its code in a .NET 3.5 project - basically back-port the newer code. I don't think we used much (if any) .NET 4 specific code in that particular project.
Is this thread relevant to these issues ??
In 3.8 Samples:
ProjectTrackerWeb.MVC will not load .... "Project Type is not Supported in this Installation"
Compiling CSLA.Web.MVC fails with ... Error 1 Cannot apply indexing with [] to an expression of type 'System.Web.Mvc.IValueProvider' C:\Projects\CSLA\cslacs\Csla\Web\Mvc\CslaModelBinder.cs 31 66 Csla.Web.Mvc
I need a reference project for using the CSLA login / membership code using VS 2008 / ASP.Net 2.0 / .Net 3.5 ... I'm able to load the ProjectTrackerMVC files into a new project .... but am concerned that the MVC "plumbing" is not compiling cleanly.
Running to meeting now ... there is more to add .... I also get compiler errors when I try to Replace the 3.8 CSLA.Web.Mvc code with 4.0 project.
Steve
Sorry .. that is ASP.Net MVC 2.0
Hello,
Have you installed the ASP.NET MVC 2.0 runtime for VS2008?
Thanks
-Blake Niemyjski
Thanks for responding ... I'm hoping to get this issue resolved today ....
Problems mentioined above were encountered after installing MVC from Web Platform Installer ...
Which is more current ( I just noticed that there is an upgrade to WPInstaller ) ..... that code or ASP.NET MVC 2 RTM - 3/12/2010
Which issues are you thinking can be resolved by your suggestion ???
Compiler error when replacing 3.8.3 CslaModelBinder with 4.0 is
Error 1 The type or namespace name 'Rules' does not exist in the namespace 'Csla' (are you missing an assembly reference?) C:\CSLA_Samples\cslacs\Csla.Web.Mvc\CslaModelBinder.cs 96 55 Csla.Web.Mvc
That is compile time error ... any workaround for that variable ???
protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var obj = bindingContext.Model as Csla.Core.BusinessBase;
if (obj != null)
{
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Csla.Rules.RuleSeverity.Error
select r;
foreach (var item in errors)
{
string mskey = CreateSubPropertyName(bindingContext.ModelName, item.Property);
bindingContext.ModelState.AddModelError(mskey, item.Description);
}
}
else
base.OnModelUpdated(controllerContext, bindingContext);
PS ... adding 4.0 Rules Namespace to 3.8.3 project raised even more compile time errors
finally got a clean compile .... Changed
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Csla.Rules.RuleSeverity.Error
select r;
to
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Csla.Validation.RuleSeverity.Error
select r;
I'm going to create another solution after downloading the CSLA 3.8.3 source and the PTWebMVCSamples ..... and do another re-load of the PtWebMVC project files into an empty MVC2.0 project .... with the above code change ....
Is that a sound approach to get a ProjectTracker MVC2.0 solution running ??
Thx,
Steve
There is also this compile error when using the 4.0 Web.Mvc in 3.8
protected virtual bool SaveObject<T>(T item, Action<T> updateModel, bool forceUpdate) where T : class, Csla.Core.ISavable
{
try
{
ViewData.Model = item;
if (updateModel != null)
updateModel(item);
ViewData.Model = item.Save(forceUpdate);
return true;
}
catch (Csla.DataPortalException ex)
{
if (ex.BusinessException != null)
ModelState.AddModelError("", ex.BusinessException.Message);
else
ModelState.AddModelError("", ex.Message);
return false;
}
catch
{
return false;
}
Error 37 No overload for method 'Save' takes '1' arguments C:\Documents and Desktop\PROJECT_TRACKER_MVC\CslaSource-4.0.0-100524\Source\Csla.Web.Mvc\Controller.cs 48 26 Csla.Web.Mvc
It will compile cleanly with this revision:
ViewData.Model = item;
if (updateModel != null)
updateModel(item);
ViewData.Model = item.Save(); <=== REMOVING forceUpdate
return true;
Any risks here ????
???
I'm still concerned that the "patches" to:
ViewData.Model = item;
if (updateModel != null)
updateModel(item);
ViewData.Model = item.Save(); <=== REMOVING forceUpdate
return true;
code change to the 3.8 Csla.Web.Mvc.Controller class
are un-tested ... could cause problems with the solution I need to deliver Using .Net 3.5 and Asp.Net MVC 2.0.
Is this the correct work-around to get a clean comile ???
Thanks,
Steve
Hello,
I'm unfamiliar with these changes. However, they do look like they should be safe todo. But, I would run the 4.0 unit tests against this and make sure that they still pass. Rocky is out on vacation, I'm not sure when he will be back...
Thanks
-Blake Niemyjski
still not clear if I am adopting the correct approach ....
Anyone else using MVC2.0 with VS2008 and CSLA 3.8 ???
thx,
Steve
Hello,
Yep, completed two large size applications with CSLA 3.8 & MVC 2.0. One with .NetFramework 3.5 other with 4.0.
I didn't use model binding with collections.
We updated the CslaModel Binder from CSLA 3.8 to work with MVC 2.0. I haven't looked into CSLA 4.0, so can't help there.
It looks like this:
protected override void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var obj = bindingContext.Model as Csla.Core.BusinessBase;
if (obj != null)
{
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Csla.Validation.RuleSeverity.Error
select r;
foreach (var item in errors)
{
bindingContext.ModelState.AddModelError(item.Property, item.Description);
bindingContext.ModelState.SetModelValue(item.Property, bindingContext.ValueProvider.GetValue(item.Property));
}
}
else
base.OnModelUpdated(controllerContext, bindingContext);
}
HTH.
Rocky -
There were a couple of responses re: this issue on this thread today, but neither of them addressed my changes
finally got a clean compile ....
Changed ( in Csla.Web.Mvc.CslaModelBinder) OnModelUpdated
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Csla.Rules.RuleSeverity.Error
select r;
to
var errors = from r in obj.BrokenRulesCollection
where r.Severity == Csla.Validation.RuleSeverity.Error
select r;
and -- in Csla.Web.Mvc.SaveObject
ViewData.Model = item;
if (updateModel != null)
updateModel(item);
ViewData.Model = item.Save(); <=== REMOVING forceUpdate
return true;
Your insights, please.
Thanks,
Steve
Hi Steve, I was on vacation the past week, and at Tech Ed the week prior, so I've been somewhat hands-off with the forum of late.
My approach with MVC 2 is to get CSLA 4 done and working, then to back-port the code to 3.8.4. There's a lot of work still occurring for MVC in CSLA 4 and I don't have the time (or desire) to maintain it twice while it is so volatile.
Other than minor tweaks though, the CSLA 4 code will be a direct back-port to 3.8 - which should affect none of the MVC code of course, just some relatively small differences around other parts of CSLA. That probably includes adding the Save(forceSave) overload to ISavable in 3.8, etc.
Surprised that this required your input, Chief. My radar says that MVC 2.0 adoption using .Net 3.5 has more momentum than .Net 4.0 and VS 2010.
Is my approach really such a "bleeding edge" use case ????? -- No one else has done a QA validation of the changes to the "boilerplate that I have made ????
I ( and I trust a significant segment of Enterprise CSLA developers ) must deal with "governance" issues around the adoption / "blessing" of .Net 4.0 and VS 2010.
Wer'e just starting to use the ModelBinder ..... I'm kinda' "betting my career on this" ..... what's the safe thing to do ????
The other solutions to the issue on this thread ... should I consider them instead of the changes that I have made to:
ViewData.Model = item.Save(); <=== REMOVING forceUpdat code change to the 3.8 Csla.Web.Mvc.Controller class
Best to all ... and special thanks to you again R. L. ...
Steve
Thanks to all ..
Steve
It is just a matter of time/priorities on my end. Magenic has a .NET 4 project using MVC, and so I have access to someone who's directly using that code and can help test/debug/improve how it works. Additionally all my time and focus has been on CSLA 4 for months now - 3.8 is technically in maintenance (bug fix) mode.
The fact that I'm back-porting MVVM and MVC constructs to 3.8 is because, as you note, most people are still using .NET 3.5 and so it is worth some level of effort to keep 3.8 reasonably up to date. But make no mistake, 3.8 is in maintenance mode and won't see the improvements in most areas that will occur in 4.
understand ... just need to know if the "patches" that I applied to get a clean compile might blow up in certain cases.
If so I'll avoid those cases.
Well I do think your forceSave change will cause an issue. Though I didn't look at it in depth - but if you don't do forceSave, then you need to re-fetch the object so you can do an update. The whole point of forceSave is to allow you to create a "new" object and then make it do an update instead of insert.
OK ... thanks Rocky .... I'm going to try here and on the LinkedIn and Facebook groups to see if I can find others who are working with CSLA 3.8 / .Net 3.5 / and ASP.Net MVC 2.0 .... can't believe that I am the "sole early adopter".
Steve
Steve,
I posted a reply to your post with the change I made to CSLA 3.8 to make it work with MVC 2.0.
I noticed you tried to copy some of the source from CSLA 4.0 and back ported to CSLA 3.8, that is probably why you are getting most of the issues. As I said, we modified CSLA 3.8 to make it work with MVC 2.0, that change should get model binding working (except for collections).
HTH.
Our app is (at this point) exclusively read-only.
But the main root BO has children and grand-children that need to talk to controls on the Views.
So ... please help me understand ... collection binding ... The code I have now [4.0 back port] is working with the ProjectTracker Project View Index.aspx .... Iterating through the Model ... collection of ProjectInfo objects.
I want to do a build doing the "back port" .... but since I know enough to "be dangerous" here ... please ... any heads up/caveats on my approach will be appreciated.
Thanks,
Steve
If you want, you can pull the 3.8.4 MVC project from svn. I just back-ported the CSLA 4 code (other than the authz stuff, which is just too different) into 3.8.
I'd appreciate any bug reports or other feedback.
will do. Thanks, Rocky.
anyone else working in this space ???
Steve
Copyright (c) Marimer LLC