ExpandoObject, anonymous types and Razor

前端 未结 4 1573
北恋
北恋 2021-01-03 04:16

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          


        
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 04:31

    Try setting the type as dynamic

    dynamic o = new ExpandoObject();
    o.stuff = new { Foo = "bar" };
    return View(o);
    

    Go through this excellent post on ExpandoObject

提交回复
热议问题