I'm using TempData to carry messages with Redirect after Post. The controller sets the tempdata as shown here:
TempData["message"]="foo";
return RedirectToAction("Index");
In the _Layout.cshtml, I have the following fragment:
@{var temp = TempData["message"] as string; }
@if ( temp != null)
{
<div class="message">@temp</div>
}
My problem is now, that after the redirect, the message is not displayed. However, on the request that follows immediately the redirect (refresh or any other page), the message is displayed. After being displayed, it is removed from the session as expected.
How can I make my TempData display on the page I redirect to?
When you do:
The message will be displayed when the Index page to which you are redirecting renders its view.