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?