我想使用ExpandoObject作为ViewPage< dynamic>类型的Razor视图的viewmodel.我这样做时出错了
ExpandoObject o = new ExpandoObject(); o.stuff = new { Foo = "bar" }; return View(o);
我该怎么做才能使这项工作?
解决方法
您可以使用此问题中提到的扩展方法来执行此操作:
Dynamic Anonymous type in Razor causes RuntimeBinderException
所以你的控制器代码看起来像:
dynamic o = new ExpandoObject(); o.Stuff = new { Foo = "Bar" }.ToExpando(); return View(o);
然后你的观点:
@model dynamic @Model.Stuff.Bar
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。