If ASP.NET MVC2 code below shows message “Test” in Create controller response.
In Mono message does not appear apper in Create view.
Message appears in next response invoked after create.
How to dorce Mono to show TempData value in same request like in ASP.NET ?
[HttpPost]
public RedirectToRouteResult Create()
{
TempData["Message"] = "Test";
return RedirectToAction("Index");
}
public ActionResult Index() {
return View();
}
Site.Master:
<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<!DOCTYPE html>
<html>
<head runat="server">
<script src="<%= Url.Content("~/Scripts/jquery/jquery-1.7.1.js")%>" type="text/javascript"></script>
<% if (TempData["Message"]!=null) {
%>
$(function() {
setTimeout( function() {
showMessage ( '<%= TempData["Message"] as string %>');
}, 300 );
});
<% } %>
</script>
</head>
I would recommend you consuming the
TempDatavalue inside the controller action and not inside the view:and inside the view:
By the way instead of using
ViewData, I would recommend you using a view model and have your view strongly typed to this view model.