简体   繁体   English

是否有可能在MVC4中将会话值从动作转移到另一个动作?

[英]Is it possible to get session values from action to another in MVC4?

Is there a way to get the values of the session in mvc4 application from the action. 有没有办法从动作中获取mvc4应用程序中的会话值。 For example Person to action Machine by getting the current person ID/Name ? 例如Person to action Machine通过获取当前人员ID /名称?

You can use and access Session as usual in a MVC application. 您可以像往常一样在MVC应用程序中使用和访问Session But I believe you are looking for a method to pass values from one action result to another, You can check TempData 但我相信您正在寻找一种方法将值从一个动作结果传递到另一个动作结果,您可以检查TempData

You can always get session values across different action methods like: 您始终可以跨不同的操作方法获取会话值,例如:

string value=Session["Name"].ToString();

Or you can use TempData to persist value across methods: 或者,您可以使用TempData在方法之间保持值:

var value= TempData["key"];
TempData.Keep();

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

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