Copied to clipboard

Flag this post as spam?

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


  • Connie DeCinko 931 posts 1160 karma points
    Mar 10, 2015 @ 22:19
    Connie DeCinko
    0

    TempData empty after return RedirectToUmbracoPage

    If I set TempData before returning a partial view, I can display the contents of TempData on the partial view so I know it kinda works.

    But, I am following the online tutorial and setting a value for TempData

    TempData.Add("CustomMessage", "Your form was successfully submitted at " + DateTime.Now);
    

    before doing

    return RedirectToUmbracoPage(2097);
    

    I have

    <p><span style="color: red;">@TempData["CustomMessage"]</span></p>
    

    in my MacroPartialView but nothing is apparently in TempData when the page displays.

  • Connie DeCinko 931 posts 1160 karma points
    Mar 11, 2015 @ 00:57
    Connie DeCinko
    0

    UPDATE: Turns out the TempData is not actually empty when the page loads. I just cannot get it to display on my parent PartialView. If I add

    <p><span style="color: blue;">@TempData["CustomMessage"]</span></p>
    

    to my edit form which is a partialview loaded by my MacroPartialView, then the next time I display the form, the TempData is displayed. It seems the TempData is tied to the view, partial or otherwise, that was visible when the TempData value was set!

    How can I get the TempData to display in the MacroPartialView that calls the form partial view?

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    @using EthicsAdmin.Controllers.SurfaceControllers
    @using EthicsAdmin.Models
    
    <p><span style="color: blue;">@TempData["CustomMessage"]</span></p>
    
    @Html.Partial("~/Views/MacroPartials/Admin/Ethics/_Opinions.cshtml")
    <br />
    <input type="button" value="Add a New Opinion" class="btn btn-default" onclick="OpenCreatePopup()" />
    <br />
    <hr />
    <br />
    <div id="opinionEditForm"></div
    

    A button click injects the edit form in that last div.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 11, 2015 @ 12:25
    Ismail Mayat
    0

    Connie,

    What version of Umbraco are you using?

     

  • Connie DeCinko 931 posts 1160 karma points
    Mar 11, 2015 @ 16:27
    Connie DeCinko
    0

    6.1.6

  • Connie DeCinko 931 posts 1160 karma points
    Mar 11, 2015 @ 23:03
    Connie DeCinko
    0

    The problem seems to be related to only being able to access the TempData in the same controller context that set the TempData value:

    TempData is a dictionary of string and object.  When the PossiblyLoadTempData is called, the TempDataDictionary uses the ControllerContext as well as the ITempDataProvider to load the data.
    

    It seems my form action is being treated as a child action to the main MacroPartialView and there for out of context.

    The Umbraco documentation at https://our.umbraco.org/documentation/Reference/Mvc/forms/turorial-child-action refers to accessing ViewData of the child in the parent. There must be some similar method to access the child TempData from the parent view.

Please Sign in or register to post replies

Write your reply to:

Draft