Copied to clipboard

Flag this post as spam?

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


  • Mathias valling 16 posts 126 karma points
    Oct 22, 2019 @ 10:49
    Mathias valling
    0

    Sending models to controller

    Hey Umbraco was hopeing if someone is able to help me out, im trying to send a model from a Pview to the controller, via BeginUmbracoForm, how ever the controller models is null.

    using (Html.BeginUmbracoForm<ViewBasketController>("ShowBasket", FormMethod.Post, new
                            {
                                model = new AddToBasketViewModel()
                                {
                                    Sku = "Jabii101",
                                    Quantity = 1,
                                    ViewBasketContent = new ViewBasketContentViewModel()
                                    {
    
                                        IntroHeader = "IntroHeader",
                                        IntroBodyText = "IntroBodyText",
                                        DiscountHeader = "DiscountHeader",
                                        DiscountBodyText = "DiscountBodyText",
                                        QuantityInfo = "QuantityInfo",
                                        InvalidFeedback = "InvalidFeedback",
                                        ShippingText = "ShippingText"
                                    }
                                }
    
                            }))
                            {
                                @*<input type="hidden" name="Sku" value="Jabii101" />
                                    <input type="hidden" name="Quantity" value="1" />*@
                                <input type="submit" class="btn btn_preorder shop_btn_hero wow fadeInUp" data-toggle="modal"
                                       value="@ButtonText" />
                            }
    

    if i use the input hidden i can pass the data but it only works for the simple strings Sku and Quantity the model is null.

    [HttpPost]
            public ActionResult ShowBasket(AddToBasketViewModel model)
            {
                var temp = "";
                if (!TransactionLibrary.HasBasket())
                {
                    Redirect("/");
                }
                    var basketModel = new PurchaseOrderViewModel();
    
    ...
    
                    return PartialView("/Views/Preorder/ViewBasket.cshtml", basketModel);
                }
    

    What am i doing wrong ? or is it even possible to do it?

    it is running 7.15 on cloud

    Really looking forward for any tips

    BR Mathias

Please Sign in or register to post replies

Write your reply to:

Draft