开发者

Is there a way to access a .NET MVC ViewBag's properties using a string key?

开发者 https://www.devze.com 2023-02-13 18:41 出处:网络
I have a value 开发者_如何学运维that I\'ve put in the ViewBag: ViewBag.SomeKey = value; In my view I have the key stored as a String.

I have a value 开发者_如何学运维that I've put in the ViewBag:

ViewBag.SomeKey = value;

In my view I have the key stored as a String.

String theKey = "SomeKey";

Is there a way to access my value from the Viewbag using this String version of the key?


Use ViewData[theKey]. Both ViewData and ViewBag use the same underlying storage.

0

精彩评论

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