我怎样才能获得TempData的对象在MVC4认识 [英] How Can I Get TempData Object Recognize in MVC4
本文介绍了我怎样才能获得TempData的对象在MVC4认识的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个创建TempData的对象
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"];}
但是,当我尝试使用VARmessage.Success编译器无法识别的属性。当我在调试期间观看VAR消息,TempData的,我可以看到该对象的txtMessage和成功的价值。我缺少什么?
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?
推荐答案
尝试
@{dynamic message = TempData["Message"];}
或
@{Message message = TempData["Message"] as Message;}
或者,如果你知道它会永远只能是一个消息
or, if you know it will only ever be a Message
@{Message message = (Message)TempData["Message"];}
这篇关于我怎样才能获得TempData的对象在MVC4认识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文