c# - how to enumerate MVC 5 viewbag -
seems viewbag instance of system.web.mvc.dynamicviewdatadictionary. internal , cant cast viewbag it. , type doesn't expose idictionary interface (cf expandoobject)
so how can this
foreach(var kv in <viewbag magic>) { ..... } i see system.web.mvc.dynamicviewdatadictionary has keys method doesn't since cannot dynamic object value dynamically. ie cant do
var k = "key1"; var v = viewbag[k];
the viewdata property -- viewdatadictionary -- contain same data viewbag (viewbag wrapper around viewdata).
a viewdatadictionary structure can iterated (it implements idictionary<string, object> , various ienumerables):
foreach (keyvaluepair<string, object> kvp in viewdata) { } there ways cast expandoobjects idictionary<string, object>s you're still in same boat, since need know types you're working cast them object useful.
Comments
Post a Comment