Copied to clipboard

Flag this post as spam?

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


  • Ahmed Ilyas 7 posts 27 karma points
    Feb 14, 2014 @ 16:03
    Ahmed Ilyas
    0

    After POST, return model?

    I am having difficulties trying to figure out why umrbaco doesnt do what i expect it to like normal MVC.

    This is what I am trying to do:

     

    I have a partial view which displays some fields from my model.

    My controller derives from SurfaceController.

    I have a template being used for that view which has the following code:

     

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "MvcBanner.cshtml";
    }
    @section ContentPlaceHolderParent { 
     @Umbraco.RenderMacro("Breadcrumb")
     
     <h1>@Umbraco.Field("pageName")</h1>
     @Umbraco.Field("pageInstructions", insertBefore: "&lt;p class=&quot;instructions&quot;&gt;", insertAfter: "&lt;/p&gt;", convertLineBreaks: true)

             @Html.Partial(@Umbraco.Field("PaymentDetails").ToString(), new MyModel())

     

    At this point, obviously the GET method in the controller does not get invoked. If I change Html.Partial to Html.Action, then it works but then has other problems, so sticking with Partial for now.

    My view uses the Html.BeginUmbracoForm("ActionName", "ControllerName") to render the form area.

    When I hit submit, it calls the POST action method. Great. I can then also use return CurrentUmbracoPage() method in the action.

    However, if the model posted needs to have its value changes or needs to preserve the data but depending on what the user checked on the form in terms of the radio button, a visible change needs to be made. Now thats easy in standard MVC - you check on the view if the model property is set to a certain value and if so then render the UI action you want to do such as show an alert box.

    however, it seems that this never happens but instead it calls the template code where I am newing up a Model thus any previous values on the page do not get preserved.

     

    any ideas why this is happening and what I am doing wrong?

    setting data in TempData does not seem to be kept there for the request so storing the model in temp data before doing a return CurrentUmbracoPage does not hold that model.

     

    if I change to using Html.BeginForm(), it breaks in that when the ModelState is not valid, and I return a PartialView(model), then the page breaks so no css, jquery etc.. gets rendered - just that partial view as a strong (and also using the Html.Action in the template in this scenario)

     

    thoughts? I'm really struggling.

  • Charles Afford 1163 posts 1709 karma points
    Feb 15, 2014 @ 13:09
    Charles Afford
    1

    So do you want to post data and then reload the partial with the data in the updated model?

  • Hannah Mathews 9 posts 79 karma points
    Nov 19, 2015 @ 17:06
    Hannah Mathews
    0

    This is exactly what i'm looking to do is there a way to do this without using the surfacecontroller?

  • Hannah Mathews 9 posts 79 karma points
    Dec 17, 2015 @ 11:08
    Hannah Mathews
    0

    To do this without the surface controller, return the model as a tempdata :
    TempData["Model"] = model;
    return RedirectToCurrentUmbracoPage();

    and in the view at the top just below the @using

    @{ this.MapModel

    I hope this helps!

Please Sign in or register to post replies

Write your reply to:

Draft