简体   繁体   中英

TempData key not found issue in asp.net core

I am using TempData to pass success or failure message in view page. When i deployed application for first time it works fine but when server gets restarted/reboot I get an session issue in TempData as like in below screenshot.

在此处输入图片说明

Thanks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM