Web API passing Object to a Get method

后端 未结 2 2119
独厮守ぢ
独厮守ぢ 2021-02-19 02:55

is there a way to pass an object as a parameter in a Get method in Web API? I have the following case:

In my Web.API project the Get method looks like that:



        
相关标签:
2条回答
  • 2021-02-19 03:19

    You need to use [FromUri] attribute.

    Look at the the following question. ASP.NET MVC Web Api Get Not Mapping QueryString To Strongly Typed Parameter

    0 讨论(0)
  • 2021-02-19 03:35

    I think that

    public IEnumerable<ArticleMetaData> GetComponentXMLByDate([FromUri]ComponentRequest request)
    {
        // Some logic here
        return articleMeta;
    }
    

    should work.

    Mike Stall has a good article on how-webapi-does-parameter-binding

    0 讨论(0)
提交回复
热议问题