有沒有一種方法可以將查詢字符串參數傳遞給ASP.NET MVC4 Web Api控制器,而無需使用此處概述的OData約定?在不使用OData約定的情況下傳遞查詢字符串參數?
http://www.asp.net/web-api/overview/web-api-routing-and-actions/paging-and-querying
我有一些倉庫使用方法小巧玲瓏不支持IQueryable的,並希望能夠手動分頁他們不使用OData的約定建的,但每當我嘗試做了傳統的ASP.NET方式我收到「路由未找到」錯誤。
例如,這裏有一個路線:
context.Routes.MapHttpRoute(
name: "APIv1_api_pagination",
routeTemplate: "api/v1/{controller}/{id}",
defaults: new { area = AreaName, controller = "category", offset = 0, count = 100});
而這裏的匹配
public class CategoryController : ApiController
{
// GET /api/<controller>
public HttpResponseMessage Get(int id, int offset = 0, int count = 0)
簽名每當我通過下面的查詢:
http://localhost/api/v1/category/1?offset=10
我得到出現以下錯誤:
No action was found on the controller 'Category' that matches the request.
任何關於如何在ASP.NET MVC4 Web API中使用querystrings的建議?
我相信這可能是WebAPI中的一個錯誤。你能否嘗試改變你的動作方法參數,使其沒有默認值(併發出一個包含查詢字符串中所有必需值的請求)。 – marcind
當然,我會試試這個。 – Aaronontheweb