我的WebApiConfig中有两条简单的路线:
config.Routes.MapHttpRoute(
name: "Speaker",
routeTemplate: "api/presentations/{presentationid}/speakers/{id}",
defaults: new { controller = "speakers", id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "Presentations",
routeTemplate: "api/presentations/{id}",
defaults: new { controller = "presentations", id = RouteParameter.Optional }
);
我无法获得第一条工作路线..我有一个带有Get的SpeakersController:
IEnumerable<SpeakerModel> Get(int presentationid)
{
return _speakerService.GetSpeakersByPresentationId(presentationid).Select(s => _modelFactory.Create(s));
}
当我通过get请求调用http://localhost/Api/Presentations/1/Speakers时,我收到此错误:
&#34;消息&#34;:&#34;未找到与请求URI匹配的HTTP资源&#39; http://localhost/Api/Presentations/1/Speakers&#39;。&#34;, &#34; MessageDetail&#34;:&#34;未在控制器上发现任何操作&#39;扬声器&#39;与请求匹配。&#34;
答案 0 :(得分:0)
我的方法上没有公共访问修饰符。
**public** IEnumerable<SpeakerModel> Get(int presentationid)
{
return _speakerService.GetSpeakersByPresentationId(presentationid).Select(s => _modelFactory.Create(s));
}