我有api呼叫路由定义为此
routes.MapHttpRoute(
name: "VisitGetByIdApi",
routeTemplate: "api/v1/visits/{id}",
defaults: new { Controller = "Visits", Action = "GetById" },
constraints: new { id = @"\d*", httpMethod = new HttpMethodConstraint(new[] { "GET", "POST" }) }
);
我试图通过ajax从我的.js文件调用web api,但是我一直收到404错误,调用的方法是什么。
self.GetVisitById = function () {
debugger;
$.ajax({
type: "GET",
url: "/api/v1/visits",
data: {
id: self.Id()
},
traditional: true,
success: function (data) {
debugger;
return data;
},
error: function (data) {
debugger;
}
});
}
消息:“找不到与请求URI”http://localhost:1059/api/v1/visits?id=5217“匹配的HTTP资源。” MessageDetail:“找不到与名为'v1'的控制器匹配的类型。”