Null TempData when passing data from controller to view MVC

Viewed 15655

I have the following class in a Controller passing data to a View:

public ActionResult ControllerToView(){
    ...
    TempData["example"] = "this is a message!";
    ...
    return Redirect("http://myViewPageLink");
}

In my View, I am trying to access the TempData dictionary with:

@if(myCondition){
    var test = TempData["example"];
    <p>@test</p>
}

"myCondition" is always satisfied, but the TempData dictionary is always empty. Any ideas why? Is there any aditional code I have to write in order to make TempData available in the view?

It might be useful information that before calling my controller method I have an ajax request to another method in the same controller.

1 Answers
Related