views:

107

answers:

3

Hi! Is there an equivalent for the ViewData/ TempData object in ASP.NET MVC for ASP.NET?

What I wanna do is to keep a Session item only alive for one request.

Thanks in advance!

Edit:

The problem is that I have one view for updating and creating. When the view is in update mode then the session item is filled or it has to be already filled(!) and in the create mode the session item is null. So when I am in creating mode and send the page back to serve the mode changed into edit mode and a button on the view is enabled because the session item was filled. The mode depends on the session item. And the Session item can be filled by another view or when I create a contact successfully. The Session item value is the contactId.

+1  A: 

ViewState is the closest you can have. it is a page-scope persistence storage but it will survive many subsequent requests to the same page.

You can adapt it to your needs. Initialize some RequestID value in page constructor and keep it in the Session tightly coupled to the Session variable you need. When reading from session, you can simply check if the identifier points to the current request or to the one of some previous generation. It's more or less how the TempData is implemented.

You can also take a look at RequestData collection. It is though kept for the duration of one request only and is not stretched to the next request.

Developer Art
A: 

You can use request object. You might also find this page helpful.

Pablo Santa Cruz
+1  A: 

For just one request? Not even a postback? Then you could just use a protected field or property.

Mike Hodnick