tempdata

Using Tempdata in ASP.NET MVC - Best practice

主宰稳场 提交于 2019-11-26 04:32:59
I am using ASP.NET MVC 3 to build a web application. What I am trying to do is pass values between two controllers, though there are many ways to do this I am particular interested in using TempData for this. public ActionResult Action1() { string someMessage; Test obj = SomeOperation(); if(obj.Valid) { someMessage = obj.UserName; } else { someMessage = obj.ModeratorName; } TempData["message"] = someMessage; return RedirectToAction("Index"); } public ActionResult Index() { ViewBag.Message = TempData["message"] return View(); } So is the use of TempData here correct ? I mean under best

TempData keep() vs peek()

自古美人都是妖i 提交于 2019-11-26 03:49:44
问题 What is the difference between keep() and peek()? MSDN says: keep(): marks the specified key in the dictionary for retention. peek(): returns an object that contains the element that is associated with the specified key, without marking the key for deletion. I can\'t get really what the difference is, don\'t they both keep a value for another request? 回答1: When an object in a TempDataDictionary is read, it will be marked for deletion at the end of that request. That means if you put something

When to use TempData vs Session in ASP.Net MVC

廉价感情. 提交于 2019-11-26 02:18:01
问题 I am trying to get the hang of MVC framework so bear with me. Right now, the only thing I\'m using the session store for is storing the current logged in user. My website is simple. For this example, consider three domain objects, Person, Meeting, and File. Users can log in and view a \"members only\" profile of a meeting and can add files to it, or view a meeting\'s public \"profile\" if they aren\'t logged in. So, from the meeting\'s private profile, with a logged in user, I have a \"add

Using Tempdata in ASP.NET MVC - Best practice

*爱你&永不变心* 提交于 2019-11-26 01:47:30
问题 I am using ASP.NET MVC 3 to build a web application. What I am trying to do is pass values between two controllers, though there are many ways to do this I am particular interested in using TempData for this. public ActionResult Action1() { string someMessage; Test obj = SomeOperation(); if(obj.Valid) { someMessage = obj.UserName; } else { someMessage = obj.ModeratorName; } TempData[\"message\"] = someMessage; return RedirectToAction(\"Index\"); } public ActionResult Index() { ViewBag.Message