tempdata

c# TempData equivalent in php

我与影子孤独终老i 提交于 2019-11-28 06:58:06
问题 I know I can explicitly set and unset a Session manually but I believe this is worth to ask. In c#, there is a dictionary called TempData which stores data until the first request. In other words, when TempData is called, it is automatically unset. For a better understanding here is an example: Controller1.cs: TempData["data"] = "This is a stored data"; Model1.cs: string dst1 = TempData["data"]; // This is a stored data string dst2 = TempData["data"]; // This string will be empty, if an

TempData won't destroy after second request

烈酒焚心 提交于 2019-11-27 22:15:37
I'm putting a value into TempData on first request in an actionfilter. filterContext.Controller.TempData["value"] = true; after that a second request comes in and I check for the value filterContext.Controller.TempData.ContainsKey("value") the value is there. Then a third request comes in and I check for the value again filterContext.Controller.TempData.ContainsKey("value") and the value is still present. Shouldn't be this value destroyed after the second request ? All request are AJAX requests. Shouldn't be this value destroyed after the second request ? Only if you read it: var value =

Store complex object in TempData

南笙酒味 提交于 2019-11-27 07:23:10
I've been trying to pass data to an action after a redirect by using TempData like so: if (!ModelState.IsValid) { TempData["ErrorMessages"] = ModelState; return RedirectToAction("Product", "ProductDetails", new { code = model.ProductCode }); } but unfortunately it's failing with the following message: ' System.InvalidOperationException The Microsoft.AspNet.Mvc.SessionStateTempDataProvider' cannot serialize an object of type 'ModelStateDictionary' to session state.' I've found an issue in the MVC project in Github , but while it explains why I'm getting this error, I can't see what would be a

ASP.NET MVC - TempData - Good or bad practice

回眸只為那壹抹淺笑 提交于 2019-11-26 21:29:01
I'm using the AcceptVerbs method detailed in Scott Gu's Preview 5 blog post for dealing with form entries in ASP.NET MVC: User gets an empty form via GET User posts the filled in form via POST to the same Action The Action validates data, takes appropriate action, and redirects to a new view So I don't have to use TempData . That said, I now have to add a 'confirm' step to this process, and it seems to require the use of TempData . For some reason, I have an aversion to using TempData -- that it is something to be designed around. Is this at all a valid concern, or am I making it up? I kind of

TempData won't destroy after second request

旧时模样 提交于 2019-11-26 20:43:50
问题 I'm putting a value into TempData on first request in an actionfilter. filterContext.Controller.TempData["value"] = true; after that a second request comes in and I check for the value filterContext.Controller.TempData.ContainsKey("value") the value is there. Then a third request comes in and I check for the value again filterContext.Controller.TempData.ContainsKey("value") and the value is still present. Shouldn't be this value destroyed after the second request ? All request are AJAX

How can I disable session state in ASP.NET MVC?

▼魔方 西西 提交于 2019-11-26 19:35:28
I would like to have a very lightweight ASP.NET MVC site which includes removing as many of the usual HttpModules as possible and disabling session state. However when I try to do this, I get the following error: The SessionStateTempDataProvider requires SessionState to be enabled. I've disabled session state in web.config: <sessionState mode="Off" /> I understand that ASP.NET MVC uses session state for TempData, but I don't need/want TempData - I just want to disable session state. Help! You could make your own ControllerFactory and DummyTempDataProvider. Something like this: public class

TempData keep() vs peek()

∥☆過路亽.° 提交于 2019-11-26 17:10:00
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? Daniel J.G. 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 on TempData like TempData["value"] = "someValueForNextRequest"; And on another request you access

Store complex object in TempData

做~自己de王妃 提交于 2019-11-26 10:41:03
问题 I\'ve been trying to pass data to an action after a redirect by using TempData like so: if (!ModelState.IsValid) { TempData[\"ErrorMessages\"] = ModelState; return RedirectToAction(\"Product\", \"ProductDetails\", new { code = model.ProductCode }); } but unfortunately it\'s failing with the following message: \' System.InvalidOperationException The Microsoft.AspNet.Mvc.SessionStateTempDataProvider\' cannot serialize an object of type \'ModelStateDictionary\' to session state.\' I\'ve found an

ASP.NET MVC - TempData - Good or bad practice

旧巷老猫 提交于 2019-11-26 07:56:45
问题 I\'m using the AcceptVerbs method detailed in Scott Gu\'s Preview 5 blog post for dealing with form entries in ASP.NET MVC: User gets an empty form via GET User posts the filled in form via POST to the same Action The Action validates data, takes appropriate action, and redirects to a new view So I don\'t have to use TempData . That said, I now have to add a \'confirm\' step to this process, and it seems to require the use of TempData . For some reason, I have an aversion to using TempData --

How can I disable session state in ASP.NET MVC?

╄→гoц情女王★ 提交于 2019-11-26 07:18:55
问题 I would like to have a very lightweight ASP.NET MVC site which includes removing as many of the usual HttpModules as possible and disabling session state. However when I try to do this, I get the following error: The SessionStateTempDataProvider requires SessionState to be enabled. I\'ve disabled session state in web.config: <sessionState mode=\"Off\" /> I understand that ASP.NET MVC uses session state for TempData, but I don\'t need/want TempData - I just want to disable session state. Help!