How should I pass multiple parameters to an ASP.Net Web API GET?

前端 未结 11 1364
温柔的废话
温柔的废话 2020-12-12 09:59

I am using the .Net MVC4 Web API to (hopefully) implement a RESTful api. I need to pass in a few parameters to the system and have it perform some action, then return a lis

11条回答
  •  有刺的猬
    2020-12-12 10:32

    I found exellent solution on http://habrahabr.ru/post/164945/

    public class ResourceQuery
    {
       public string Param1 { get; set; }
       public int OptionalParam2 { get; set; }
    }
    
    public class SampleResourceController : ApiController
    {
        public SampleResourceModel Get([FromUri] ResourceQuery query)
        {
            // action
        }
    }
    

提交回复
热议问题