Copied to clipboard

Flag this post as spam?

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


  • Craig O'Mahony 364 posts 918 karma points
    Oct 12, 2015 @ 15:54
    Craig O'Mahony
    0

    Return model back to partial view

    Wonder if someone could help me out here......

    Basically what I'm trying to do if on the posting of a form, I'm doing some custom validation and if the data being submitted doesn't conform to the business then I'd like to stop processing (obviously!) and pass the incoming model back to the view that contains the form so that the user doesn't have to re-key all of their data.

    The way that I'm set this up is :

    1) I've created the model/properties. 2) I've then created a strongly-typed partial view and selected the model class that I'd just created (named AwardsCeremony) 3) I've then created a controller with the following Index ActionResult:

        public ActionResult Index()
        {
            TempData["priceList"] = getPrices();
            TempData["qualificationList"] = getQualifications();
    
            return PartialView("AwardsCeremony", new AwardsCeremonyViewModel());
        }
    

    4) Then in the Umbraco template I'm calling the controller

    @Html.Action("Index", "AwardsCeremonySurface")
    

    (this umbraco inherits it's styling, etc from the Master template (in Umbraco)).

    In the view (on the HTTPPOST event) I'm calling the processBooking actionresult on the controller.

    @using (Html.BeginUmbracoForm("processBooking", "AwardsCeremonySurface", null, new { @class = "form-horizontal" }))
    

    This ActionResult then does the error checking and that's where the problems start (!), I've removed my custom validation for ease of reading.

        [HttpPost]
        public ActionResult processBooking(AwardsCeremonyViewModel model)
        {
            //Do the custom error handling
    
            if (myInvalidForm == true)
            {
                return PartialView("AwardsCeremony",model);
            }
    
            //Process the booking
    
            return RedirectToCurrentUmbracoPage();
        }
    

    What's happening is that when the partial view is returned back the styling of the page is lost, the form displayed but with none of the inherited styling, classes, etc from the Umbraco Master template and I just don't know how to fix. Could someone point me in the right direction please?

    Thanks, Craig

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Oct 15, 2015 @ 21:38
    Marc Goodson
    0

    Hi Craig

    If you have validation errors and want to return the user back to the Umbraco page with the ModelState intact, (to show error messages and retain part filled in form fields) , you can return CurrentUmbracoPage...

    return CurrentUmbracoPage();
    

    regards

    marc

Please Sign in or register to post replies

Write your reply to:

Draft