Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dee 118 posts 338 karma points
    May 02, 2020 @ 10:34
    Dee
    0

    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() });
            }
    }
    

    View:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<SubscriptionModel>
    

    ...

    @Html.Partial("_Subscription", Model)
    @Html.Partial("_SelectCompanySize", Model);
    @Html.Partial("_SubscriptionForm")
    

    PartialView:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<SubscriptionModel>
    @using Core.Models.Subscription
    
    <div id="companysize-dialog" class="zoom-anim-dialog mfp-hide">
        <div class="small-dialog-header text-center">
            <h3>Angebote und Konditionen</h3>
        </div>
    
        @using (Html.BeginUmbracoForm("ActionName", "ControllerName", System.Web.Mvc.FormMethod.Post, new { id = "formCompanySize", data_ajax = "true", data_ajax_method = "POST", data_ajax_mode = "replace", data_ajax_loading = "#divLoading", data_ajax_success = "selectionDone" }))
        {
            <div class="text-center">
                <p class="nomargin">Bitte wähle deine Unternehmensgröße aus:</p>
                <div class="form-group add_top_10">
                    @Html.DropDownListFor(x => x.CompanySizeModel.CompanySize, Model.CompanySizeModel.CompanySizes, "Bitte wählen", new { @class = "wide" })
                </div>
    
                <div class="add_top_60">
                    <button class="btn_1 add_top_30" id="btnSize">Angebote und Konditionen sehen</button>
                </div>
            </div>
        }
    
    </div>
    

    Exception:

    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.

    Thanks

    Dee

  • Tajamal 87 posts 175 karma points
    Oct 07, 2020 @ 06:04
    Tajamal
    0

    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.

  • Dee 118 posts 338 karma points
    Oct 07, 2020 @ 09:57
    Dee
    0

    Hi Tajamal,

    yes, you need to add this to your model:

    public SubscriptionModel() : base(Umbraco.Web.Composing.Current.UmbracoHelper.AssignedContentItem) { }
    

    This implements the constructor without parameters and takes the current umbraco page as content for the base class.

    Hope this helps!

    Dee

Please Sign in or register to post replies

Write your reply to:

Draft