你的方法沒有什麼意義,爲什麼你會以Get ....開頭的方法返回void?
而且,這些路線:
http://example.com/customers/internalId=34
http://example.com/customers/externalId='JohnDoe
從MVC /網頁API的角度無效。這是它們應該如何的樣子:
http://example.com/customers?internalId=34
http://example.com/customers?externalId=John
默認的Web API路由應區分兩者並將其路由到不同的操作。
編輯:
創建下面的模板作用:
[HttpGet]
public string InternalId(int id)
{
return id.ToString();
}
定義路由的Web API:
config.Routes.MapHttpRoute(
name: "Weird",
routeTemplate: "{controller}/{action}={id}",
defaults: new { id = RouteParameter.Optional }
);
這允許你寫:
http://localhost:7027/values/internalId=12
試試吧......
然後,你可以添加另一種方法:
[HttpGet]
public string ExternalId(string id)
{
return id;
}
這:
http://localhost:7027/values/externalId=bob
也能發揮作用。
顯然,我的控制器的名稱是ValuesController,因爲我剛剛使用默認的Web Api模板測試了這一點。
感謝您指出方法中的錯誤。雖然我意識到查詢字符串可以工作,但這不是我正在尋找的。我想做些什麼鏈接在這裏完成:https://developer.linkedin.com/documents/profile-api, http://api.linkedin.com/v1/people/id=abcdefg, http: //api.linkedin。com/v1/people/url = –
darthjit
2013-03-19 13:44:41
我已經更新了我的帖子,告訴你如何做你想做的事情。如果你密切關注我所定義的路線,我相信你會明白。 – 2013-03-19 14:10:23