tempdata

TempData persisting after read in ASP.NET MVC 2

心不动则不痛 提交于 2019-11-30 18:21:54
问题 In ASP.NET MVC 2, TempData values persist until the session ends or until they are read. In the words of Microsoft... The value of TempData persists until it is read or until the session times out. Persisting TempData in this way enables scenarios such as redirection, because the values in TempData are available beyond a single request. I thought I understood this but I just came across unusual behavior in my application where a TempData value was available and it should not have been

Where does TempData get stored?

本秂侑毒 提交于 2019-11-30 17:20:46
Where does TempData get stored in the ASP.NET MVC Framework (more specifically, ASP.NET MVC 2)? Is it stored at server-side, or is sent to the client? By default TempData uses the ASP.NET Session as storage. So it is stored on the server ( InProc is the default). But you could define other ASP.NET Session state modes: StateServer and SqlServer. You could also write a custom TempData provider and handle the storage yourself if you don't want to use the ASP.NET Session. It is stored in session storage, but there is one crucial difference between TempData and Session : TempData is available only

How to check TempData value in my view after a form post?

房东的猫 提交于 2019-11-30 13:55:02
问题 I fill my TempData from a FormCollection and then I try to check the value of my TempData in my view with MVC 4 but my if statement isn't working as I expect. Here is my code. Controller : [HttpPost] public ActionResult TestForm(FormCollection data) { TempData["username"] = data["var"].ToString(); //data["var"] == "abcd" return RedirectToAction("Index"); } View: @if (TempData["var"] == "abcd") { <span>Check</span> //Never displayed } else { @TempData["var"]; // Display "abcd" } This looks

How to check TempData value in my view after a form post?

浪子不回头ぞ 提交于 2019-11-30 08:34:58
I fill my TempData from a FormCollection and then I try to check the value of my TempData in my view with MVC 4 but my if statement isn't working as I expect. Here is my code. Controller : [HttpPost] public ActionResult TestForm(FormCollection data) { TempData["username"] = data["var"].ToString(); //data["var"] == "abcd" return RedirectToAction("Index"); } View: @if (TempData["var"] == "abcd") { <span>Check</span> //Never displayed } else { @TempData["var"]; // Display "abcd" } This looks like really simple and I don't understand why I can't display this Check . Can you help me ? Please try

ASP.NET TempData persists between requests

血红的双手。 提交于 2019-11-30 06:01:05
问题 I am using temp data as follow in my controllers - very simple, when there is a problem: TempData("StatusMessage") = "You have no items set to Auto-Ship." Then on every page I have a user control as follows: <div class="error-container"> <% If TempData.ContainsKey("ErrorMessage") Then%> <script> $('div.error-container').show();</script> <div class="msg-error"><p><%=TempData("ErrorMessage") %></p></div> <% End If%> <% If TempData.ContainsKey("StatusMessage") Then%> <script> $('div.error

Where does TempData get stored?

怎甘沉沦 提交于 2019-11-30 00:57:45
问题 Where does TempData get stored in the ASP.NET MVC Framework (more specifically, ASP.NET MVC 2)? Is it stored at server-side, or is sent to the client? 回答1: By default TempData uses the ASP.NET Session as storage. So it is stored on the server ( InProc is the default). But you could define other ASP.NET Session state modes: StateServer and SqlServer. You could also write a custom TempData provider and handle the storage yourself if you don't want to use the ASP.NET Session. 回答2: It is stored

c# TempData equivalent in php

别来无恙 提交于 2019-11-29 12:49:04
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 exception is not raised (I can't remember well if an exception is raised) So basically, this is just

Asp.net core TempData give 500 error when adding list and redirect to another view

a 夏天 提交于 2019-11-29 12:28:09
问题 I am try to build alerts list and added them to TempData . But it work if I did not do redirect. When I do redirect it give me 500 error. I set break point in view as well but it did not hit when did redirect other wise it hit correctly. ActionMethod public IActionResult Create(CategoryCreateVM input) { if (ModelState.IsValid) { var category = mapper.Map<Categories>(input); categoryBL.Add(category); List<Alert> alert = new List<Alert>(); alert.Add(new Alert("alert-success", "success message")

MVC C# TempData

早过忘川 提交于 2019-11-29 11:28:00
问题 Can somebody please explain the purpose of TempData in MVC. I understand it behaves like ViewBag but what does it do beyond that. 回答1: TempData is meant to be a very short-lived instance, and you should only use it during the current and the subsequent requests only! Since TempData works this way, you need to know for sure what the next request will be, and redirecting to another view is the only time you can guarantee this. Therefore, the only scenario where using TempData will reliably work

ASP.NET TempData persists between requests

情到浓时终转凉″ 提交于 2019-11-28 13:26:56
I am using temp data as follow in my controllers - very simple, when there is a problem: TempData("StatusMessage") = "You have no items set to Auto-Ship." Then on every page I have a user control as follows: <div class="error-container"> <% If TempData.ContainsKey("ErrorMessage") Then%> <script> $('div.error-container').show();</script> <div class="msg-error"><p><%=TempData("ErrorMessage") %></p></div> <% End If%> <% If TempData.ContainsKey("StatusMessage") Then%> <script> $('div.error-container').show();</script> <div class="msg-status"><p><%=TempData("StatusMessage")%></p></div> <% End If%>