开发者

Dynamic TempData in ASP.NET MVC 3

I'vm been trying to get a开发者_开发技巧 site running using ASP.NET MVC 3 and I came across the new dynamic ViewModel. It's great to pass values quickly to the view without using "magic strings". I'm wondering if there's something similar for the TempData that keeps it's values after a RedirectToAction.

Thanks.


TempData is not dynamic in MVC 3 (as long as I can tell anyway) e.g. this syntax does not compile :

TempData.Account = "Geronimo"

because Account property/field does not exists on the type.

ViewBag Is dynamic

ViewBag.Acount = "Geronimo" 

compiles.


You can enable the session state as was used in web forms and use that to store the data if you want, is this something you would be interested in? Just google "session state in asp.net mvc"

When you do this...

TempData("test") = "cool string"

You can access is later on using tempdata.test (though they aren't sure if they are going to keep it as tempdata or going to change it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜