Using System.Dynamic in Roslyn

后端 未结 5 1863
死守一世寂寞
死守一世寂寞 2020-12-05 03:28

I modified the example that comes with the new version of Roslyn that was released yesterday to use dynamic and ExpandoObject but I am getting a compiler error which I am no

5条回答
  •  粉色の甜心
    2020-12-05 04:11

    ASP.NET MVC specific:

    You can get this error in an MVC 6 controller if you forget to put [FromBody] in a POST method.

        [HttpPost("[action]")]
        public void RunReport([FromBody]dynamic report)
        {
            ...
        }
    

    The .NETCore default project already includes Microsoft.CSharp reference but you get pretty much the same message.

    With [FromBody] added you can now post JSON and then just dynamically access the properties :-)

提交回复
热议问题