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

前端 未结 11 1395
温柔的废话
温柔的废话 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:41

    Just add a new route to the WebApiConfig entries.

    For instance, to call:

    public IEnumerable Get(int pageNumber, int pageSize) { ..
    

    add:

    config.Routes.MapHttpRoute(
        name: "GetPagedData",
        routeTemplate: "api/{controller}/{pageNumber}/{pageSize}"
    );
    

    Then add the parameters to the HTTP call:

    GET ///Api/Data/2/10 
    

提交回复
热议问题