In MVC most of the interviewer ask what is TempData and what is the usage of the TempData in otherwords they ask typically like Can TempData preserve the data on every request? Here we see the TempData how it works and how it save the data on each request. Well the answer for the above question is YES TempData can preserve the data on next request. How the TempData persist the data,it has four ways Not Read. Normal Read. Read and Keep. Peek and Read. Condition 1 (Not read):- If you set a “TempData” inside your action and if you do not read it in your view then “TempData” will be persisted for the next request. Condition 2 ( Normal Read) :- If you read the “TempData” normally like the below code it will not persist for the next request. stringstr = TempData[“MyData”]; Even if you are displaying it’s a normal read like the code below. Hide Copy Code @TempData[“MyData”]; Condition 3 (Read and Keep) :- If...
Posts
Showing posts from April, 2015