How to get GET parameters with ASP.NET MVC ApiController

后端 未结 8 1403
挽巷
挽巷 2021-01-07 16:54

I feel a bit absurd asking this but I can\'t find a way to get parameters for a get request at /api/foo?sort=name for instance.

In the ApiControll

8条回答
  •  南方客
    南方客 (楼主)
    2021-01-07 17:27

    if we have a proper model for that request

    for example

      public class JustModel 
        {
          public int Id {get;set;}
          public int Age {gets;set;}
        }
    

    and query like this

    /api/foo?id=1&Age=10
    

    You could just use [FromUri] attribute

    For example

    public IHttpActionResult GetAge([FromUri] JustModel model){}
    

提交回复
热议问题