在我的apicontroller中,我有两种方法可以处理Post请求:
public WatchListItemDTO Post(MovieDto movie)
{
//do smt..
}
[HttpPost]
[Route("MarkMovieAsWatched/{id}")]
public void MarkMovieAsWatched(int id)
{
// do smt..
}
控制器具有前缀属性:[RoutePrefix("api/DownloadList")]
。当我向http://localhost:4229/api/DownloadList/MarkMovieAsWatched/
发出(发布)请求时,它会点击我的Post
方法。该请求还包含一个对象:{id: 12}
。
我的WebApiConfig
:
public static void Register(HttpConfiguration config)
{
config.EnableCors();
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// To disable tracing in your application, please comment out or remove the following line of code
// For more information, refer to: http://www.asp.net/web-api
config.EnableSystemDiagnosticsTracing();
}
有人可以向我解释为什么方法MarkMovieAsWatched
没有被击中?以及如何解决这个问题?