简体   繁体   English

控制器属性ASP.NET Core

[英]Controller Properties ASP.NET Core

Have 2 pages for one long process. 有2页,需要一个漫长的过程。 Both in one controller. 都在一个控制器中。 My problem is: In first page, using angular - run method that generate some data. 我的问题是:在首页中,使用angular-run方法生成一些数据。 Store that data in property in controller. 将该数据存储在控制器的属性中。 Move to another page, using angular - run another method and that is... my data in property is null. 使用angular移动到另一页-运行另一种方法,即...我的property数据为null。 Is there a solution to store data in controller properties in thid situation? 有没有在这种情况下将数据存储在控制器属性中的解决方案?

New instance of a controller is created on every request so whatever you save in property of your controller this will be destroyed together with a controller when request is ended. 在每个请求上都会创建一个控制器的新实例,因此在请求结束时,无论您保存在控制器属性中的什么内容都将与控制器一起销毁。 You have to store this data either on client(cookie, local storage) or server side (session, cache, database etc.). 您必须将此数据存储在客户端(cookie,本地存储)或服务器端(会话,缓存,数据库等)上。

With ASP.Net MVC, you can't store data in a property between 2 actions. 使用ASP.Net MVC,您不能在两次操作之间将数据存储在属性中。

For achieving this, you have to use cache strategy. 为此,您必须使用缓存策略。 Please, see this link . 请查看此链接

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

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