tempdata

TempData: Is It Safe?

心不动则不痛 提交于 2019-12-03 22:29:32
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. Yes, TempData is backed by session storage, so if you are in a load balanced environment extra care must be taken when using it (sticky sessions, persistent session state, etc). TempData

Copy ModelState Errors to TempData & Display them In the view

假如想象 提交于 2019-12-03 17:31:15
Most of my action methods return PartialViews on success and RedirectToAction results on failure. For that, I would like to copy the model state errors into TempData so I could display them to the user. I've read several questions here on SO and some external links but none of them worked for me... I'm decorating the ActionMethod with ModelStateToTempData attribute from MvcContrib, then displaying it as follows in the view: (this is just a prototype) @if (TempData.Count > 0) { foreach (var obj in TempData) { var errors = ((ModelStateDictionary)obj.Value).Values; foreach (var error in errors) {

ASP.NET MVC does browser refresh make TempData useless?

蓝咒 提交于 2019-12-03 09:51:47
问题 If I redirect to a new page passing TempData to initialise the page it works fine, however if the user presses the refresh button in their browser the TempData is no-longer available. Given this, is there any situation where TempData could be used reliably? Or any way to remove or mitigate the problem of users refreshing? 回答1: In MVC 1, yes, temp data is lost after the next request after you store a key. With MVC 2 however, the temp data is lost after the first attempt to access it. You can

ASP.NET MVC does browser refresh make TempData useless?

半城伤御伤魂 提交于 2019-12-03 01:32:46
If I redirect to a new page passing TempData to initialise the page it works fine, however if the user presses the refresh button in their browser the TempData is no-longer available. Given this, is there any situation where TempData could be used reliably? Or any way to remove or mitigate the problem of users refreshing? In MVC 1, yes, temp data is lost after the next request after you store a key. With MVC 2 however, the temp data is lost after the first attempt to access it. You can always use Session, which TempData uses anyway, to solve the temp data loss issue your having. From the MVC 2

Should I be passing values through RedirectToAction or TempData?

我们两清 提交于 2019-12-02 01:27:09
问题 I've seen some articles (even MSDN) suggest TempData for passing data between ActionMethods. But I've seen others here say that TempData should be avoided. What's the best practices way to approach this? Here's some code to show my situation. Note: I'm 100% sure, I'm doing this wrong. Which is why I'm here. :) Also, I've been doing Webforms up until recently. Note2: This is related, but not the same. View: <div> @using (Html.BeginForm("Previous", "Home", new {month = @month}, FormMethod.Post)

Should I be passing values through RedirectToAction or TempData?

白昼怎懂夜的黑 提交于 2019-12-01 22:25:44
I've seen some articles (even MSDN) suggest TempData for passing data between ActionMethods. But I've seen others here say that TempData should be avoided. What's the best practices way to approach this? Here's some code to show my situation. Note: I'm 100% sure, I'm doing this wrong. Which is why I'm here. :) Also, I've been doing Webforms up until recently. Note2: This is related, but not the same. View: <div> @using (Html.BeginForm("Previous", "Home", new {month = @month}, FormMethod.Post)) { <input id="previous" type="submit" value="Previous" /> } // This fails but that's another situation

TempData not working when published to Azure

不羁岁月 提交于 2019-12-01 19:10:31
I have a site I'm playing with to get the hang of Razor Pages. I have a weird situation I'm unsure what is happening or how to resolve. I'm using [TempData] to pass a message on redirect. The app works perfectly locally. Once published to Azure I add a new item and the item is added, I'm redirected to the index page but I never see the TempData message. Here is my Index page: public class IndexModel : PageModel { private readonly TheFishRoom_MVC_Core.Data.FishRoomDbContext _context; public IndexModel(TheFishRoom_MVC_Core.Data.FishRoomDbContext context) { _context = context; } public IList

What is TempData collection used for in asp.net MVC? [duplicate]

陌路散爱 提交于 2019-12-01 04:12:36
What is the actual use of TempData collection in asp.net MVC, I need pros and cons of that collection, and when do I need to use it, which views it is shared upon, or any useful information about it, finally if someone can tell me when to use it rather than ViewData? Thanks in advance CLOSED as exact duplicate of Difference Between ViewData and TempData? TempData is used to share data between controller actions. If your controller does a RedirectToAction and the target action needs data (perhaps a particular model instance) to act upon, you can store this data in TempData. Using TempData is

ASP.NET MVC TempData in browser cookie

↘锁芯ラ 提交于 2019-12-01 03:50:04
问题 I am trying to use a custom ITempDataProvider provider to store TempData in a browser's cookie instead of session state. However, everything works fine except that I am unable to remove the cookie from the Response stream after reading it. Any ideas? Thanks! public class CookieTempDataProvider : ITempDataProvider { internal const string TempDataCookieKey = "__ControllerTempData"; HttpContextBase _httpContext; public CookieTempDataProvider(HttpContextBase httpContext) { if (httpContext == null

What is TempData collection used for in asp.net MVC? [duplicate]

China☆狼群 提交于 2019-12-01 01:56:05
问题 This question already has answers here : Closed 11 years ago . What is the actual use of TempData collection in asp.net MVC, I need pros and cons of that collection, and when do I need to use it, which views it is shared upon, or any useful information about it, finally if someone can tell me when to use it rather than ViewData? Thanks in advance CLOSED as exact duplicate of Difference Between ViewData and TempData? 回答1: TempData is used to share data between controller actions. If your