Copied to clipboard

Flag this post as spam?

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


  • Nhan Pham 14 posts 84 karma points
    Apr 21, 2016 @ 08:57
    Nhan Pham
    0

    I create partial view and using surfacecontroller.

    But I want to post model back to View after post function. I can't return model back to view.

    My code:

    Controller: enter image description here

    View: enter image description here

    Before POST:

    enter image description here

    Input data

    enter image description here

    After POST:

    enter image description here

    After POST data not save. It will reset.

    I already use "CurrentUmbracoPage"

  • Dennis Adolfi 1082 posts 6444 karma points MVP 5x c-trib
    Apr 21, 2016 @ 09:36
    Dennis Adolfi
    0

    Hi Nhan!

    Try:

    return RedirectToCurrentUmbracoPage();
    

    About return CurrentUmbracoPage() (By Markus Knappen Johansson):

    Generally you want to return to the current page if you want to keep the POST-data that was sent to the controller.

    About return RedirectToCurrentUmbracoPage() (By Shannon Deminick.):

    If your POST is successful, you shouldn't just return a response, you should redirect to a page so you can avoid the aweful issue of having a user press refresh and have it resubmit the POST

    http://www.enkelmedia.se/blogg/2014/5/8/currentumbracopage-or-redirecttocurrentumbracopage.aspx

    Best of luck to you, let me know if it works out for you!

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Apr 21, 2016 @ 09:42
    Bo Damgaard Mortensen
    0

    In addition to Dennis's post: also consider: return RedirectToCurrentUmbracoUrl(); if you're passing in querystring parameters for your page, these will be preserved.

  • Nhan Pham 14 posts 84 karma points
    Apr 21, 2016 @ 09:51
    Nhan Pham
    0

    Hi Denis.

    I want to return model to View back. I arealdy using return CurrentUmbracoPage(); If using return RedirectToCurrentUmbracoPage(); my model data will be lost.

    But I use return CurrentUmbracoPage(); data from model cannot pass to View.

    Please help me

  • Dennis Adolfi 1082 posts 6444 karma points MVP 5x c-trib
    Apr 21, 2016 @ 10:01
    Dennis Adolfi
    0

    Since you have the form in a partialview, i dont think you can edit the model thatĀ“s beeing passed in and then return it to the currentpage, since your currentpageĀ“s model is not CheckCodeModel, but probobly of type UmbracoTeplatePage or UmbracoViewPage.

    If you where to re-buildthe form to a Ajax formpost you could return the model CheckCodeModel to the same partial view and not having to do a postback. Read more about Ajax formposts with Umbraco here: http://www.systenics.com/blog/creating-an-ajax-enabled-contact-form-in-umbraco-6-with-aspnet-mvc-4-and-twitter-bootstrap/?tag=Umbraco+6

    Another way would be to pass the values back to the view in a TempData object instead of ViewBags, since Tempdata objects "survives" the redirect.

  • Nhan Pham 14 posts 84 karma points
    Apr 21, 2016 @ 10:20
    Nhan Pham
    0

    Can I do that without partial view?

    Write in template page?

  • Dennis Adolfi 1082 posts 6444 karma points MVP 5x c-trib
    Apr 21, 2016 @ 10:08
    Dennis Adolfi
    0

    Controller:

        [ChildActionOnly]
        public ActionResult Index()
        {
        var code = (string)(TempData["code"] ?? "sjfkldsf");
        return PartialView("_CheckCode", new CheckCodeModel() { Code = code });
        }
    
    [HttpPost]
    [NotChildAction]
    public ActionResult Index(CheckCodeModel model)
    {
    TempData["code"] = Model.Code;
    TempData["name"] = "djhfkjdfkdjfkdjf";
    return RedirectToCurrentUmbracoPage();
    }
    

    View:

    <div>@Html.Raw(Model != null ? Model.Code : "")</div>
        <div>@Html.Raw(TempData["name"])</div>
    
  • Nhan Pham 14 posts 84 karma points
    Apr 21, 2016 @ 10:26
    Nhan Pham
    0

    Thank Denis!

    But I want pass ModelState to View, etc.

    I will try another solution.

  • Dennis Adolfi 1082 posts 6444 karma points MVP 5x c-trib
    Apr 21, 2016 @ 10:57
    Dennis Adolfi
    0

    I see. Then look at doing it with Ajax Form, that will work with ModelState.

    Good luck to you!

Please Sign in or register to post replies

Write your reply to:

Draft