在asp.net核心中找不到TempData密钥问题

时间:2020-11-25 11:59:25

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.

我正在使用TempData在视图页面中传递成功或失败消息。当我第一次部署应用程序时,它工作正常但是当服务器重新启动/重新启动时,我在TempData中遇到会话问题,如下面的屏幕截图所示。

在asp.net核心中找不到TempData密钥问题

Thanks

1 个解决方案

#1


0  

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将被丢弃。这对于一次性消息很有用,例如表单验证错误。需要注意的重要一点是,这适用于会话中的下一个请求,因此请求可能发生在不同的浏览器窗口或选项卡中。

TempData is generally used to paas the values between controllers.

TempData通常用于在控制器之间设置值。

You should use ViewBag or ViewData to pass the value from controller to a view.

您应该使用ViewBag或ViewData将值从控制器传递到视图。

like

ViewBag.YourKey = "Value" 

on CSHTML

@if(ViewBag.YourKey!=null)
{
}

or with ViewData

或者使用ViewData

ViewData["YourKey"] = "Value" 

on CSHTML

@if(ViewData["YourKey"] !=null)
{
}

Thanks

#1


0  

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将被丢弃。这对于一次性消息很有用,例如表单验证错误。需要注意的重要一点是,这适用于会话中的下一个请求,因此请求可能发生在不同的浏览器窗口或选项卡中。

TempData is generally used to paas the values between controllers.

TempData通常用于在控制器之间设置值。

You should use ViewBag or ViewData to pass the value from controller to a view.

您应该使用ViewBag或ViewData将值从控制器传递到视图。

like

ViewBag.YourKey = "Value" 

on CSHTML

@if(ViewBag.YourKey!=null)
{
}

or with ViewData

或者使用ViewData

ViewData["YourKey"] = "Value" 

on CSHTML

@if(ViewData["YourKey"] !=null)
{
}

Thanks