我想在我的控制器中有两个Web API方法。其中一个用于在标题中使用MyViewModel
对象调用GET,另一个则不使用。GET和无参数GET导致AmbiguousActionException?
MyController.cs:
[Produces("application/json")]
[Route("api/[controller]")]
public class MyController : Controller
{
[HttpGet]
public IEnumerable<UserModel> Get()
{
// ...
}
[HttpGet]
public IEnumerable<UserModel> Get(MyViewModel viewModel)
{
// ...
}
}
但浏览到Chrome中的路由地址不传递任何MyViewModel
给了我这个错误:
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
MyController.Get (MyProject)
MyController.Get (MyProject)
如果我注释掉的参数方法,把一个破发指向参数化函数并浏览到api URL,它看起来像是viewModel
是null
就像我预料的那样,它似乎是一个新的MyViewModel
对象用参数1 ess构造函数。似乎它可能与我的问题有关。
我对Microsoft.AspNetCore V1.1.2和Microsoft.AspNetCore.Mvc V1.1.3运行。