State management in MVC 2
I want to show a Session Variable data on View. How can i achieve it. I 开发者_StackOverflow社区am storing some data in Session varaibles and noew i want to display it on View please help me.
I am new Asp.Net MVC 2
Please suggest.
use the ViewData and pass it to the view
in your controller set up something like ViewData["namehere"] = value
then in your View you can call the value of Viewdata["name here"] - think of the ViewData as a bag that you can put properties and their values into and not need to explicitly pass the viewdata to the view for the view to use it
view data is just like session in asp.net so in your controller you can create more than one view data then create you view ,if you want to create a partial control for the view it will alse see the result of the view data but do not forget to cast the result.
精彩评论