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 
德科雷該方法在控制器