tempdata

Asp.Net core Tempdata and redirecttoaction not working

自闭症网瘾萝莉.ら 提交于 2021-02-20 05:50:24
问题 I have a method in my basecontroller class that adds data to tempdata to display pop-up messages. protected void AddPopupMessage(SeverityLevels severityLevel, string title, string message) { var newPopupMessage = new PopupMessage() { SeverityLevel = severityLevel, Title = title, Message = message }; _popupMessages.Add(newPopupMessage); TempData["PopupMessages"] = _popupMessages; } If the action returns a view, this works fine. If the action is calling a redirectotoaction I get the following

Is it good practice to pass TempData and/or ViewData to services?

China☆狼群 提交于 2020-02-04 15:56:50
问题 In trying to reduce the size of my MVC controllers, I am refactoring a lot of logic out into services (though this same issue would apply if it was being factored into models). I'm often finding that I was directly setting ViewData and/or TempData with information I wanted to be displayed to the user, like: var repoUser = new UserRepository(); var foundUser = repoUser.GetUser(userId); if (foundUser == null) { ViewData["ErrorMessage"] = "Could not find user with ID {0}.".FormatWith(userId);

MVC pass model between Parent and Child Window

橙三吉。 提交于 2020-01-16 10:37:30
问题 Thanks in advance. Please excuse me for my grammer. I tried my best to explain my issue In my quest of solving below question I started to develop a POC first. C# MVC No submit pass object between views I am having an issue using TempData object and pass my model between my parent popup and child popup. My problem is I am doing TempData["StudentViewModel"] 2 times. First time insert and First time read are good but Second time read even though I make sure that I insert second time before read

equivalent of ASP.NET MVC TempData in ASP.NET

喜你入骨 提交于 2020-01-02 04:32:09
问题 In ASP.NET MVC, there's a TempData which can pass data one time from one page to another. What's the equivalent for this in ASP.NET? 回答1: There is no direct equivalent (that is, data that is only passed to the next page). You can use Session and clear it out on the receiving page. 回答2: You can use either Session or Viewstate to pass data between pages in ASP.NET application. 来源: https://stackoverflow.com/questions/6198037/equivalent-of-asp-net-mvc-tempdata-in-asp-net

ASP.NET MVC 3 Custom Action Filter - How to add incoming model to TempData?

青春壹個敷衍的年華 提交于 2020-01-01 16:10:29
问题 I'm trying to build a custom action filter which grabs the incoming model out of the filter context, adds it to tempdata, then does "other stuff". My action method looks like this: [HttpPost] [MyCustomAttribute] public ActionResult Create(MyViewModel model) { // snip for brevity... } Now, i want to add the model to TempData , after the model-binding has kicked in and transformed the form value collection into MyViewModel . How do i do that? public override void OnActionExecuting

ASP.NET MVC Store TempData in Cookie

只愿长相守 提交于 2020-01-01 10:05:11
问题 Is there a way to let TempData store in a browser's cookie instead of Session State. I have Session State disabled on my site. Thanks. 回答1: Nazaf, try this for removing your cookies: public void DeleteCookie(string name) { DateTime now = DateTime.UtcNow; string cookieKey = name; var cookie = new HttpCookie(cookieKey, null) { Expires = now.AddDays(-1) }; HttpContext.Response.Cookies.Set(cookie); } usage: DeleteCookie("__ControllerTempData"); 回答2: You can use brock Allen's Cookie TempData

TempData: Is It Safe?

梦想的初衷 提交于 2020-01-01 07:33:14
问题 I am using the TempData in order to preserve my model in when using a RedirectToAction . It works fine, but I have a nagging feeling that it might not be the right thing to do. I really try to avoid using Session data, and I've read that TempData uses the Session. Is it safe to use? Are there issues which might arise in using it in a load balanced environment? Trivia Question: "Is It Safe?"-- name the movie. 回答1: Yes, TempData is backed by session storage, so if you are in a load balanced

Implementing ITempDataProvider vs Using Cookies

会有一股神秘感。 提交于 2019-12-24 13:14:44
问题 I am trying to use TempData to send data from one request to another. However, since TempData uses a server session, and this application is to be web-farmed, I will have to either use cookies or database persistance, instead, since the session won't transfer from one server to the other. There are a number of implementations available to use cookies instead of the default session: public class CookieTempDataProvider : ITempDataProvider { const string CookieName = "TempData"; public void

ASP.NET MVC CookieTempDataProvider.DeserializeTempData returns null

蓝咒 提交于 2019-12-23 12:17:42
问题 I've been trying to use CookieTempDataProvider to pass a basic message between a post (entity update) and a get (entity list) using the RedirectToAction method. When using the default TempData implementation this works fine, however when I use the cookie-based version from the MVC Futures project, the TempData dictionary is empty after the redirect. This is because the TempDataDictionary is returned as null from the DeserializeTempData method. I know exactly what line of code the problem