ExpandoObject, anonymous types and Razor

前端 未结 4 1572
北恋
北恋 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:36

    Using the open source Dynamitey (in nuget) you could make a graph of ExpandoObjects with a very clean syntax;

      dynamic Expando = Build.NewObject;
    
      var o = Expando (
          stuff: Expando(foo:"bar")
      );
    
      return View(o);
    

提交回复
热议问题