{"id":99,"date":"2014-05-09T09:58:00","date_gmt":"2014-05-09T08:58:00","guid":{"rendered":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/09\/what-is-tempdata-in-mvc\/"},"modified":"2014-05-09T09:58:00","modified_gmt":"2014-05-09T08:58:00","slug":"what-is-tempdata-in-mvc","status":"publish","type":"post","link":"https:\/\/debuggersspace.com\/index.php\/2014\/05\/09\/what-is-tempdata-in-mvc\/","title":{"rendered":"What is tempData in MVC?"},"content":{"rendered":"<div class='booster-block booster-read-block'>\n                <div class=\"twp-read-time\">\n                \t<i class=\"booster-icon twp-clock\"><\/i> <span>Read Time:<\/span>45 Second                <\/div>\n\n            <\/div><div dir=\"ltr\" style=\"text-align: left;\">\n<div style=\"background-color: white; color: #111111;\">\n<b><span style=\"font-family: Arial, Helvetica, sans-serif;\">TempData:<\/span><\/b><\/div>\n<div style=\"background-color: white; color: #111111;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">TempData is also a dictionary derived from TempDataDictionary class and stored in short lives session and it is a string key and object value. The difference is that the life cycle of the object. TempData keep the information for the time of an HTTP Request. This mean only from one page to another.<\/span><\/div>\n<div style=\"background-color: white;\">\n<\/div>\n<ul style=\"text-align: left;\">\n<li><span style=\"color: #111111; font-family: Arial, Helvetica, sans-serif;\">when you redirect, \u201cTempdata\u201d helps to maintain data between those redirects.<\/span><\/li>\n<li><span style=\"color: #111111; font-family: Arial, Helvetica, sans-serif;\">It internally uses session variables.<\/span><\/li>\n<li><span style=\"color: #111111; font-family: Arial, Helvetica, sans-serif;\">It requires typecasting for complex data type and check for null values to avoid error.<\/span><\/li>\n<li style=\"box-sizing: border-box; padding: 5px 0px; text-align: justify;\">\n<div style=\"box-sizing: border-box; padding: 0px; vertical-align: top;\">\n<span style=\"font-family: Arial, Helvetica, sans-serif;\">It\u2019s life is very short and lies only till the target view is fully loaded.<\/span><\/div>\n<\/li>\n<li style=\"box-sizing: border-box; padding: 5px 0px; text-align: justify;\">\n<div style=\"box-sizing: border-box; padding: 0px; vertical-align: top;\">\n<span style=\"background-color: #f9f9f9; color: #161616; font-family: Arial, Helvetica, sans-serif; line-height: 24px;\">It is used to store only one time messages like error messages, validation messages.&nbsp;<\/span><\/div>\n<\/li>\n<\/ul>\n<p><\/p>\n<pre lang=\"cs\" style=\"border: 1px solid rgb(251, 237, 187); overflow: auto; padding: 6px; white-space: pre-wrap; word-wrap: break-word;\"><span style=\"background-color: white;\"><span style=\"font-family: Arial, Helvetica, sans-serif;\"><span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">public<\/span> ActionResult Index()\n{\n  <span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">var<\/span> model = <span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">new<\/span> Review()\n            {\n                Body = <span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">\"<\/span><span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">Start\"<\/span>,\n                Rating=5\n            };\n    TempData[<span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">\"<\/span><span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">ModelName\"<\/span>] = model;\n    <span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">return<\/span> RedirectToAction(<span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">\"<\/span><span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">About\"<\/span>);\n}\n&lt;pre&gt;&lt;pre lang=<span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">\"<\/span><span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">cs\"<\/span>&gt;<span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">public<\/span> ActionResult About()\n{\n    <span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">var<\/span> model= TempData[<span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">\"<\/span><span style=\"border: 0px; color: purple; margin: 0px; padding: 0px;\">ModelName\"<\/span>];\n    <span style=\"border: 0px; color: blue; margin: 0px; padding: 0px;\">return<\/span> View(model);\n}<\/span><\/span><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>TempData: TempData is also a dictionary derived from TempDataDictionary class and stored in short lives session and it is a string key and object value. The difference is that the life cycle of the object. TempData keep the information for the time of an HTTP Request. This mean only from one page to another. when [&hellip;]<\/p>\n","protected":false},"author":43,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[37],"tags":[],"class_list":["post-99","post","type-post","status-publish","format-standard","hentry","category-mvc"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false},"uagb_author_info":{"display_name":"Himanshu Namdeo","author_link":"https:\/\/debuggersspace.com\/author\/admin\/"},"uagb_comment_info":0,"uagb_excerpt":"TempData: TempData is also a dictionary derived from TempDataDictionary class and stored in short lives session and it is a string key and object value. The difference is that the life cycle of the object. TempData keep the information for the time of an HTTP Request. This mean only from one page to another. when&hellip;","_links":{"self":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/99"}],"collection":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/users\/43"}],"replies":[{"embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/comments?post=99"}],"version-history":[{"count":0,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/posts\/99\/revisions"}],"wp:attachment":[{"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/media?parent=99"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/categories?post=99"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/debuggersspace.com\/index.php\/wp-json\/wp\/v2\/tags?post=99"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}