I want to use an ExpandoObject as the viewmodel for a Razor view of type ViewPage<dynamic>. I get an error when I do this
ExpandoObject o = new ExpandoObject();
o.stuff = new { Foo = "bar" };
return View(o);
what can I do to make this work?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
And then your view: