Uses Of Temp Data and Keep and Peek |
|
Hi,
I am new to MVC and its concepts. Now i started using ViewBag, Temp Data to maintain the data in the web page.
Is TempData is session? can any one please share crisp answer?
Thanks for your time and help.
|
JonesStar |
Answered# (0)
|
Reply For This Question
|
|
|
Answer(s) Posted
|
|
Temp Data and its uses. Peek and Keep in TempData
|
|
View Data, View Bag and TempData are used for passing data from controller to view and for next/subsequent requests.
"TempData" Keeps data between requests. Given examples below,
Saving data in TempData:
TempData["Key"] = "MyData"; // This TempData keeps value till the next request accessing this key.
Read TempData - Method 1:
var data = TempData["Key"]; // after getting the data, this TempData will be marked for deletion.
Read TempData - Method 2:
var data = TempData.Peek("Key"); // data in the TempData will persists for the next access.
Keep TempData:
var data = TempData["Key"]; // after getting the data, this TempData will be marked for deletion.
TempData.Keep("Key"); // after above accessing the value, by doing like this, TempData["Key"] will not be marked for deletion
|
Raj Kumar
| Answered# (13)
|
|
|
Post Your Answer
|
Please login to post your answer.
|
|
|