How Can I Get TempData Object Recognize in MVC4

asp.net-mvc-4, c#

Solution

try

@{dynamic message = TempData["Message"];}

or

@{Message message = TempData["Message"] as Message;}

or, if you know it will only ever be a Message

@{Message message = (Message)TempData["Message"];}

Problem

I have an ActionMethod that creates TempData object ``` TempData["Message"] = new Message {Text = txtMessage, Success = false}; ``` Then I read the TempData in the view like ``` @{var message = TempData["Message"];} ``` But when I try to use the var "message.Success" the compiler doesn't recognize the property. When I watch the var message and TempData during debug I can see the Object's txtMessage and Success value. What am I missing?

Original source