0

我有困难有一个web api控制器的帮助页面填充。在控制器的唯一方法如下:asp.net mvc web api帮助页面没有填充给定的路线

public HttpResponseMessage Get(string p1,string p2= "blend", string p3 = "blend") 

的方法出现反射的带有签名的帮助页面:

GET api/mycontroller?p1={p1}&p2={p2}&p3={p3} 

但是没有我的意见流向的帮助页面。对于其他简单的控制器Get(string id)帮助页面正常工作。

我尝试添加以下的WebApiConfig.cs

config.Routes.MapHttpRoute( name: "mycontroller", routeTemplate: "api/mycontroller/{p1}/{p2}/{p3}", defaults: new { p1 = RouteParameter.Optional, p2 = RouteParameter.Optional, p3 = RouteParameter.Optional
} );

但还是帮助页面是没有得到与总结,PARAM描述或回写的评论填充。

回答

1

而不是试图解决这与设置基于约定的路由,我会使用attribute routing

首先启用它在WebApiConfig.cs

config.MapHttpAttributeRoutes(); 

然后与路线

[HttpGet] 
[Route("api/mycontroller")] 
public HttpResponseMessage Get1(string p1, string p2= "blend", string p3 = "blend") 
//Call this api/mycontroller?p1=valueOne&p2=valueTwo&p3=valueThree 

[HttpGet] 
[Route("api/mycontroller/{p1}/p2/p3")] 
public HttpResponseMessage Get2(string p1,string p2= "blend", string p3 = "blend") 
//Call this api/mycontroller/valueOne/valueTwo/valueThree 
德科雷该方法在控制器