Asp.net Core TempData lifetime and search term

前端 未结 1 814
醉梦人生
醉梦人生 2021-01-21 13:49

In my index I added a search field.

When user enter a search term and click filter the index (Index) is filtered. So far so good.

What I would like to achieve

1条回答
  •  隐瞒了意图╮
    2021-01-21 14:35

    Judging by many older Stack Overflow posts and articles out there, it seems TempData only lasted until the next request in prior versions of ASP.NET. However, that is not the case as of .NET Core according to Microsoft:

    ASP.NET Core exposes the Razor Pages TempData or Controller TempData. This property stores data until it's read in another request. The Keep(String) and Peek(string) methods can be used to examine the data without deletion at the end of the request. Keep marks all items in the dictionary for retention.

    Another claim I see repeatedly about TempData is how it is implemented using sessions, but that isn't the default mechanism as of .NET Core:

    The cookie-based TempData provider is enabled by default. To enable the session-based TempData provider, use the AddSessionStateTempDataProvider extension method.

    Source: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-3.1#tempdata

    0 讨论(0)
提交回复
热议问题