I use TempData and ViewData to display messages for an asp mvc application. They are part of the Site Master. For some reason, neither TempData or ViewData are showing any information. They do work as expected in the development environment bu开发者_Python百科t not in production.
Any ideas of what setting I need to be looking at?
The code is like this:
<% if (TempData["errorMsg"] != null)
{ %>
<h2><%= TempData["errorMsg"]%></h2>
<% } %>
TempData
relies on the Session
behind the scenes, so if you have it disabled, or cookies disabled it might not work. As for the ViewData
, if you set a value in the controller action there's no reason this value wouldn't show up in the view.
Do you have any more information?
Can you be sure that the TempData for errorMsg is being set and not just empty?
Add some logging to your actions and see if the code you expect is realy excuting. I use log4net http://logging.apache.org/log4net/index.html
You should use Keep or Peek methods to retrieve TempData for multiple times. Because if “TempData” is once read it will not be available in the subsequent request. For your code I think use of Peek method is more suitable.
<h2><%= TempData.Peek("errorMsg").ToString() %></h2>
精彩评论