In Mvc This 3 object work like property and use in view and controller. basic use is get and pass value means communication between view controller. using this you can get or set chuck amount of data.
like here is Example
// Comment viewdata["Name"]="Bhavik Solucky"; viewbag.Name="Bhavik Solucky"; tempdata["Name"]="Bhavik Solucky";
now here I have one view which display this value
// Comment Temp: @TempData["Name"] ViewData: @ViewData["["Name"];"] viewbag:viewbag.Name;
but basic difference of all 3 variable is that if you want to redirect from one view to other view then tempdata will contain value and other view doesn’t contain any detail.
suppose redirect from home view to customer view then tempdata contain value but viewbag and view data become null
more detail check this link :http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications
so when you know redirect request that time temp data is very useful
No comments:
Post a Comment