In my specific example, I need to pass an error received on one controller to another controller where it will be display. Here is a test case I set up. I've tried TempData, ViewData and Session. One other thing I noticed is that maybe it's the way I'm redirecting. When I put a breakpoint on the receiving controller if I just go to it I hit the breakpoint, but on the redirect it never hits.
Sending Controller Action
public ActionResult New()
{
Session["Notice"] = "There was an error";
Session["NoticeClass"] = "error";
return RedirectToAction("Index", "Home");
}
Then here's the receiving controller:
public ActionResult Index()
{
//Handle action
return View();
}
Then a partial view renders out any errors or notices found
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<%
string Message = "";
string Class = "hidden";
if (ViewData["Notice"] != null && ViewData["Notice"] != "")
{
Message = (string)ViewData["Notice"];
Class = (string)ViewData["NoticeClass"];
}
if (Session["Notice"] != null && Session["Notice"] != "")
{
Message = (string)Session["Notice"];
Class = (string)Session["NoticeClass"];
Session["Notice"] = null;
}
Response.Write("<div class=\"" + Class + "\" id=\"error_div\"><span id=\"error_span\">" + Message + "</span></div>");
%>