简体   繁体   English

在ASP.NET Core中找不到TempData密钥问题

[英]TempData key not found issue in asp.net core

I am using TempData to pass success or failure message in view page. 我正在使用TempData在视图页面中传递成功或失败消息。 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中遇到了会话问题,如下面的屏幕截图所示。

在此处输入图片说明

Thanks 谢谢

TempData is discarded after the next request completes. 下一个请求完成后,将丢弃TempData。 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. TempData通常用于在控制器之间设置值。

You should use ViewBag or ViewData to pass the value from controller to a view. 您应该使用ViewBagViewData将值从控制器传递到视图。

like 喜欢

ViewBag.YourKey = "Value" 

on CSHTML 在CSHTML上

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

or with ViewData 或与ViewData

ViewData["YourKey"] = "Value" 

on CSHTML 在CSHTML上

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

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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