有没有办法使用字符串键访问.NET MVC ViewBag的属性?

Ric*_*ide 5 viewbag asp.net-mvc-3

我有一个我放在ViewBag中的值:

ViewBag.SomeKey = value;
Run Code Online (Sandbox Code Playgroud)

在我看来,我将密钥存储为String.

String theKey = "SomeKey";
Run Code Online (Sandbox Code Playgroud)

有没有办法使用键的String版本从Viewbag访问我的值?

mar*_*ind 6

使用ViewData[theKey].双方ViewDataViewBag使用相同的底层存储.