TempData is discarded after the next request completes. This is useful for one-time messages, such as form validation errors. The important thing to take note of here is that this applies to the next request in the session, so that request can potentially happen in a different browser window or tab.
TempData
is generally used to paas the values between controllers.
You should use ViewBag
or ViewData
to pass the value from controller to a view.
like
ViewBag.YourKey = "Value"
on CSHTML
@if(ViewBag.YourKey!=null)
{
}
or with ViewData
ViewData["YourKey"] = "Value"
on CSHTML
@if(ViewData["YourKey"] !=null)
{
}
Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.