2

I have a Csla.Net parent + list of child model and in my grid I'm binding to a collection of child records of type BusinessBase. Using Kendo grid inline grid editing, the Update method fails during the model binding as it cannot create an instance of an interface.

This problem is on the Parent property, which on a Csla.Net child object is defined as Csla.Core.IParent in the base class.

Now I get it that the model binder is struggling here as it cannot possibly spin up an interface.

My thought is that sure, I can flatten or reshape the models here and use a viewmodel to work around this, but is there any way to stop the Parent property either serializing down into the grid in the first place or configure the grid to ignore the Parent property when posting back?

Here's some Fiddler output showing the error.

[MissingMethodException: Cannot create an instance of an interface.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.Activator.CreateInstance(Type type) +66
   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +554

[MissingMethodException: Cannot create an instance of an interface. Object type 'Csla.Core.IParent'.]
   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +630
   Csla.Web.Mvc.CslaModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +119
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1135
   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +631
   Csla.Web.Mvc.CslaModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +206
   Castle.Proxies.Invocations.DefaultModelBinder_BindModel.InvokeMethodOnTarget() +199
   Castle.DynamicProxy.AbstractInvocation.Proceed() +117

Thanks.

Kurenai Kunai
  • 1,842
  • 2
  • 12
  • 22
richardb
  • 943
  • 1
  • 10
  • 27
  • I think the problem is that my object is complex and Kendo grid binding does not support complex objects. The solution I believe is to flatten and simplify using a viewmodel, have the grid bind to the viewmodel and map it back into the complex model later in the controller. – richardb May 27 '15 at 10:50
  • I agree, that is the correct answer. – Rockford Lhotka Jun 09 '15 at 04:53

0 Answers0