所以我,做來回在同一個MVC應用程序爲m角碼到web API控制裝置的呼叫,像這樣角調用的WebAPI不打斷點
$http.get('/api/lime/').success(function (data) {
$scope.line = data;
$scope.$apply();
}).error(function (jqXhr, status, errorThrown) {
//$('#lblMessage').text(errorThrown).show();
});
它工作正常了,居然打Web API實際用於獲取數據的類中的斷點,但不會觸及控制器。 T'm不傳遞一個id,所以它打到第二個不帶參數的httpget。控制器在下面。注意:LimeLoader()。GetLimes()行是在解決方案中調用一個類來調用數據。我在這堂課中有一個斷點,它很好。
public class LimeController : ApiController
{
[HttpGet]
public LimeLoader GetLime(int id)
{
return new LimeLoader(id);
}
[HttpGet]
public IEnumerable<LimeLoader> GetLimes()
{
return new LimeLoader().GetLimes().ToList();
}
}
,路線如下:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
從第二HTTPGET方法返回集合,但爲什麼沒有被擊中控制器我的斷點?提前致謝。
問題真的很混亂。你在哪裏設定了斷點? – Win
你能顯示你的路線配置嗎?如果您使用web api 2,我發現使用屬性路由更容易。 – Ionian316
在發佈之前,您需要重讀您的問題。你在哪裏試圖通過Angular傳遞「id」? (); – granadaCoder