0

I am learning MVC and testing the keep and peek methods of Tempdata. Keep() method returning me the value of tempdata across postback but peek() method not returning value across postback. Also, I set the value to tempdata and in view, I didn't read that value but still across postback it didn't persist. I have used exact code used in the tutorial. It's working over there but not working in my machine. Is there any issue with VS because only peek() method is not working. Heres my controller code:

public class TempDataController : Controller
{
    // GET: TempData
    public ActionResult ShowTempData()
    {
        TempData["Test"] = "Showing Value Of TempData";
        return View();
    }
}

And heres my view code:

 <div>
    @{ 
        string str = TempData.Peek("Test").ToString();
    }

    @str;

</div>

I don't see issue with this code. Can you please tell me?

Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Kishor Kulkarni
  • 41
  • 1
  • 12
  • Just clarify "its working over there but not working in my machine" => are you want to say that the `Peek()` method **only** not working in dev environment? – Tetsuya Yamamoto Oct 17 '18 at 07:43
  • [link](https://stackoverflow.com/a/21254178/6311571) That will help you to understand Peek along with Keep – Ziaul Kabir Fahad Oct 17 '18 at 09:21
  • @TetsuyaYamamoto Thanks for your reply and sorry for my bad english. I am watching online video tutorials and doing practice. What i mean is the teacher of video tutorials uses same above code and its working properly on his machine but its not working on my machine. – Kishor Kulkarni Oct 17 '18 at 09:56
  • @ZiaulKabirFahad thanks for your reply. The link is very helpful. What i am saying is i havent read the value of tempdata in above code. So if i refresh my page then inside my controller i should get value of TempData["Test"]. But i am getting null value for the same. – Kishor Kulkarni Oct 17 '18 at 09:58

0 Answers0