Custom Model causes system.missingmethodexception in beginUmbracoForm
Hi,
following scenario:
Model:
public class SubscriptionModel : ContentModel
{
public SubscriptionModel(IPublishedContent content) : base(content) { }
public CompanySizeModel CompanySizeModel { get; set; }
public int PlanLevel { get; set; }
public IEnumerable<Plan> Plans { get; set; }
}
Controller:
public class SubscriptionController : RenderMvcController
{
public override ActionResult Index(ContentModel model)
{
return base.Index(new SubscriptionModel(model.Content) { CompanySizeModel = new CompanySizeModel() });
}
}
System.MissingMethodException: Für dieses Objekt wurde kein
parameterloser Konstruktor definiert. Object type
'Core.Models.Subscription.SubscriptionModel'. --->
System.MissingMethodException: Für dieses Objekt wurde kein
parameterloser Konstruktor definiert. bei
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean
publicOnly, Boolean noCheck, Boolean& canBeCached,
RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) bei
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean
skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) bei
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly,
Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
bei System.Activator.CreateInstance(Type type, Boolean nonPublic)
bei System.Activator.CreateInstance(Type type) bei
System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext
controllerContext, ModelBindingContext bindingContext, Type modelType)
--- Ende der internen Ausnahmestapelüberwachung --- bei System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext
controllerContext, ModelBindingContext bindingContext, Type modelType)
bei
System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext
controllerContext, ModelBindingContext bindingContext) bei
System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext
controllerContext, ModelBindingContext bindingContext) bei
System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext
controllerContext, ParameterDescriptor parameterDescriptor) bei
System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext
controllerContext, ActionDescriptor actionDescriptor) bei
System.Web.Mvc.Async.AsyncControllerActionInvoker.<>cDisplayClass31.0(AsyncCallback
asyncCallback, Object asyncState) bei
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallBeginDelegate(AsyncCallback
callback, Object callbackState) bei
System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback
callback, Object state, Int32 timeout) bei
System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext
controllerContext, String actionName, AsyncCallback callback, Object
state) bei
System.Web.Mvc.Controller.<>c.
Everytime the form tries to call the surface controller action, it causes a system.missingmethodexception, since my custom model does not have a constructor with no parameter, which is the way it should be done due to the documentation. What should I do here? And why is my form trying to create the model again, although the model was passed from the view to the partial view and shouldn't be created again for the form submit.
Hi Dee
Did you figure out ?
i am having the same issue creating a surface controller.
Absolutely nothing is working and action is blank when i use Html.Beginform.
Custom Model causes system.missingmethodexception in beginUmbracoForm
Hi,
following scenario:
Model:
Controller:
View:
...
PartialView:
Exception:
Everytime the form tries to call the surface controller action, it causes a system.missingmethodexception, since my custom model does not have a constructor with no parameter, which is the way it should be done due to the documentation. What should I do here? And why is my form trying to create the model again, although the model was passed from the view to the partial view and shouldn't be created again for the form submit.
Thanks
Dee
Hi Dee Did you figure out ? i am having the same issue creating a surface controller. Absolutely nothing is working and action is blank when i use Html.Beginform.
Hi Tajamal,
yes, you need to add this to your model:
This implements the constructor without parameters and takes the current umbraco page as content for the base class.
Hope this helps!
Dee
is working on a reply...