1
我已经添加了这个方法我的网络API控制器:ASP.net的Web API 2自定义方法
[HttpPost]
public bool CreateTrening(int routineId)
{
try
{
var userId = User.Identity.GetUserId();
TreningService.CheckIfLastTrenigWasCompleted(userId);
TreningService.CreateTreningForUser(userId, routineId);
return true;
}
catch (Exception ex)
{
return false;
}
}
而且我已经加入到我的WebApiConfig文件另一条路线,所以它现在看起来是这样的:
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "CustomApi",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
但是当我尝试打电话给我的方法:
/EditWorkout/CreateTrening/1
我得到这个呃ror:
{“Message”:“没有找到与请求URI相匹配的HTTP资源”/EditWorkout/CreateTrening/1'.","MessageDetail":"没有在控制器的EditWorkout上找到匹配的操作请求。“}
如何调用我在WebApi控制器中的方法?