0

In java I'm able to have object that are Session scoped and view scoped. In asp.net mvc it seems that all data are request scoped? How can I make data view scoped and even session scoped?

I would like to have my ViewModels view scoped so I don't have to make fields for all values in the view, and better support for nested view models.

For session scope I would like to have one object following the user through the entire sessions which can hold information about the user (more than I can get from the identity user object).

Is this possible?

Izzet Yildirim
  • 640
  • 1
  • 11
  • 19

1 Answers1

0

What do you exactly mean by not making fields for all values?

About storing in session, yes it is possible and has already been answered: How to access session variables from any class in ASP.NET?

You can also make them application scoped, as in Java: https://msdn.microsoft.com/en-us/library/aa348545(v=vs.100).aspx

Community
  • 1
  • 1
SaraFlower
  • 755
  • 1
  • 8
  • 15
  • If I have a view model object which is passed to the view - the view model (A) contain a list of another view model (B). By passing A to the view I have to do some extra work to ensure the list containing B's is populated on post back. I would also like to have the controllers view scoped so I can store values within the controller while user is interacting views within the controller. – Søren Bjerg Christensen Apr 09 '17 at 20:09