Copied to clipboard

Flag this post as spam?

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


  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 19, 2015 @ 10:43
    Sören Deger
    0

    TempData is always empty

    Hello,

    my TempData in a view is already empty: "Enumeration yielded no results".

    I set the TempData in my controller:

    TempData["loginFailed"] = "error";
    return RedirectToCurrentUmbracoPage();
    

    And I will check the TempData in my view:

    @if(TempData["loginFailed"] != null)
    {
                        <p>Login failed!</p>
    }
    

    Umbraco Version: 7.2.8

    I search for a solution since a few hours, but can't figure it out how it will works. The same code I have use a lot of times before without problems.

    Has anyone an idea?

    Cheers, Sören

  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 19, 2015 @ 11:45
    Sören Deger
    0

    More details:

    The view is a partial view and it's rendered within the grid editor. If I will check the TempData in the master view it works. But if I will check the TempData in the Partial View it doesn't work.

    How I can get the TempData value in a partial view which is rendered from grid editor?

    Cheers, Sören

  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 23, 2015 @ 14:56
    Sören Deger
    0

    No good solution, but a temporary workaround:

    Now, we use a session variable instead of TempData.

  • Anne Uth 23 posts 43 karma points
    Sep 29, 2015 @ 07:43
    Anne Uth
    0

    I have the exact same problem. Im trying to render a macro through the grid, but after the post to the surfacecontroller the TempData is always empty.

    Could you show me your code on how you have done it with the session variable as a temporary fix?

  • Sören Deger 733 posts 2844 karma points c-trib
    Sep 29, 2015 @ 07:51
    Sören Deger
    0

    Hi Anne,

    you can set a session variable like this:

    Session["mySessionVar"] = "myValue";
    

    Then check if the Session exist and has a specific value:

    if(Session["mySessionVar"]!=null && Session["mySessionVar"]=="myValue")
    {
        // enter code here
    
        // and set the session variable to null if you don't need this anytime
        Session["mySessionVar"] = null;
    }
    

    Hope this helps?

    Best, Sören

  • Anne Uth 23 posts 43 karma points
    Sep 29, 2015 @ 07:56
    Anne Uth
    0

    I just have the problem that my macro gets rendered two times after a post (I dont know why). So i do not have any options to clear the session.

  • Sanjay 7 posts 27 karma points
    Jun 25, 2016 @ 11:36
    Sanjay
    0

    hi has anyone had any luck finding a solution to this? I have the same issue where im setting tempdata in the controller and its always empty in the macro i am using for the view.

Please Sign in or register to post replies

Write your reply to:

Draft