TempData not migrated during RedirectToAction

I have an interesting problem with an object TempDatanot passing values ​​to another controller.

I set TempData["Enroll"]in the method Enroll Controller HttpPostfor the model Enroll. Then I read the object TempData["Enroll"]in the method Register Controller HttpGet, but empty/ null.

I need to save all this data on three controllers.

Any thoughts?

Here is a snippet of code

EnrollController.cs
[HttpPost]
public ActionResult Index(EnrollModel model)
{
   ...
   TempData["EnrollModel"] = model;
   return RedirectToAction("Index", "Register");
}

RegisterController.cs
public ActionResult Index(string type)
{
    RegisterModel model = new RegisterModel();

    EnrollModel enrollModel = TempData["EnrollModel"] as EnrollModel;
    model.ClientType = enrollModel.ClientType;
    ...
}
+5
source share
4 answers

I came across these limitations with TempData before. At best, I found it unrealistic and sporadic.

, . , - ( ), , .

:

  • - RegisterController, , .

  • , db ? , , / , , .

+1

.

, RedirectAction HTTP 302 , temp, HTTP- 303 ( , RedirectAction) 307, .

TempData sessionState web.config StateServer InProc. :

<system.web>
    <sessionState mode="StateServer" cookieless="AutoDetect" timeout="30" stateConnectionString="tcpip=localhost:42424"></sessionState>
    ...
</system.web>

, , TempData TempDataProvider, MongoDB , .

, 4- - .

+1

, TempData .

web.config sessionState Setting, InProc , , .

, web.config, . :

<httpCookies requireSSL="true" />

requireSSL false TempData .

+1

db / . TempData , reset, , , .

, null ref:

EnrollModel enrollModel = TempData["EnrollModel"] as EnrollModel;
if(enrollModel==null)
{
//handle this model being null
}
model.ClientType = enrollModel.ClientType;

, , , , , - , / .

0

All Articles