【发布时间】:2017-05-19 16:06:25
【问题描述】:
我在这里尝试实现多个 Get 方法,但浏览器出现错误Multiple actions were found that match the request。为什么会这样?
在 Api Controller 中,我添加了两个方法: 1. GetEmployee 2. HelloDept 如果我注释掉其中一个,它工作正常。
public class TrailController : ApiController
{
private IProduct Repo = new Product();
[HttpGet]
public IEnumerable<Employee> GetEmployee()
{
var x = Repo.GetEmp();
return x;
}
[HttpGet]
public IEnumerable<Department> HelloDept()
{
var x = Repo.GetDept();
return x;
}
RouteConfig.cs
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{api}/{controller}/{action}/{id}",
// defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
defaults: new {id = RouteParameter.Optional }
);
【问题讨论】:
标签: asp.net-web-api