【发布时间】:2013-10-16 06:46:14
【问题描述】:
我有一个看起来像这样的控制器
[HttpGet]
[ActionName("Ping")]
public bool Ping() { return true; }
[HttpPost]
[ActionName("Test")]
public string Test([FromBody] Testing form)
{
return form.Email + " " + form.Password;
}
在运行帮助页面时会显示:
获取 api/测试
POST api/测试
路由是模板附带的默认路由,所以不确定为什么即使在放置注释“ActionName”之后它也没有选择正确的名称。
任何帮助将不胜感激。
================================================ ==================
回答: 正如 David L. 所建议的,问题在于路由。我阅读了他建议的链接并添加了一个包含“ACTION”的新路由 API,它看起来像这样:
config.Routes.MapHttpRoute(
name: "TestApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
现在它可以使用正确的注解名称显示正确的 API。
【问题讨论】:
标签: c# asp.net-web-api