I want to use an ExpandoObject as the viewmodel for a Razor view of type ViewPage
. I get an error when I do this
ExpandoObject o
You can do it with the extension method mentioned in this question:
Dynamic Anonymous type in Razor causes RuntimeBinderException
So your controller code would look like:
dynamic o = new ExpandoObject();
o.Stuff = new { Foo = "Bar" }.ToExpando();
return View(o);
And then your view:
@model dynamic
@Model.Stuff.Bar