2
是否有可能采取行动?是否可以在Web API .net中使用params进行操作?
[HttpGet]
public List<Product> GET(int CategoryId, string option, params string[] properties)
{
List<Product> result = new List<Product>();
result = BusinessRules.getProductsByCategoryId(CategoryId);
return result;
}
从而使URL看起来像“/ API /产品/类别编号/全/名称/产品ID /”
它调用可能的动作,因为属性是可选的,但在性能参数总是空。我甚至尝试过在请求的主体中传递Name和ProductID参数,而仍然属性为null。我想使用“params”,因为我想将0..N的论述传递给动作。
这里是路线模板。
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{CategoryId}/{option}/{*properties}",
constraints: new { CategoryId = @"\d+" },
defaults: new { option = RouteParameter.Optional, properties = RouteParameter.Optional }
);