I was found Controller.TempData Property that make possible store some data between different ControllerActions. I was implement simple Wizard application using MVC framework. and using TempData store data on each step.
But I not understand how TempData works. it NOT register any hiddenfield in HTML, so i appologize that it store on server side.
Where? it is safe for use same data from one session( from several Tabs in browser for example )? what is "by design" use cases for TempData?
//New.aspx:
<% if(TempData.ContainsKey("ErrorMessage") { %>
Error happened: <%= TempData["ErrorMessage"] %>
<% } %>
rest of the HTML ...
In that case, the RedirectToAction("New") will cause a new request from the browser to the New() action which will see the TempData and show it. Any subsequent requests will not see that TempData item.
mogadanez
Member
73 Points
49 Posts
Controller TempData - How it works?
Dec 23, 2007 08:18 PM|LINK
I was found Controller.TempData Property that make possible store some data between different ControllerActions. I was implement simple Wizard application using MVC framework. and using TempData store data on each step.
But I not understand how TempData works. it NOT register any hiddenfield in HTML, so i appologize that it store on server side.
Where? it is safe for use same data from one session( from several Tabs in browser for example )? what is "by design" use cases for TempData?
sergiopereir...
Member
227 Points
61 Posts
Re: Controller TempData - How it works?
Dec 23, 2007 09:37 PM|LINK
TempData store objects in the Session just for the next request.
One use case is to pass data to the next request and redirect the current request to another action:
[ControllerAction] public void Create(int id) { Product prod = new Product(); prod.UpdateFrom(Request.From); if(prod.Validate()) { prod.Save(); RedirectToAction("List"); } else { TempData["ErrorMessage"] = "Invalid entry. Try again."; RedirectToAction("New"); } }In that case, the RedirectToAction("New") will cause a new request from the browser to the New() action which will see the TempData and show it. Any subsequent requests will not see that TempData item.
Sergio Pereira
http://devlicio.us/blogs/sergio_pereira/