ViewBag is of type dynamic , but internally System.Dynamic.ExpandoObject()
It is declared as follows:
dynamic ViewBag = new System.Dynamic.ExpandoObject();
therefore you can:
ViewBag.Foo = "Bar";
Expander Expander Object Code:
public class ExpanderObject : DynamicObject, IDynamicMetaObjectProvider { public Dictionary<string, object> objectDictionary; public ExpanderObject() { objectDictionary = new Dictionary<string, object>(); } public override bool TryGetMember(GetMemberBinder binder, out object result) { object val; if (objectDictionary.TryGetValue(binder.Name, out val)) { result = val; return true; } result = null; return false; } public override bool TrySetMember(SetMemberBinder binder, object value) { try { objectDictionary[binder.Name] = value; return true; } catch (Exception ex) { return false; } } }
Aniket Inge Feb 20 '13 at 17:15 2013-02-20 17:15
source share