大家好,我的控制器 api 中有 2 个方法:
[HttpPost]
[HttpGet]
public IEnumerable<Hotel> Get(HotelSearch hotelSearch)
{
try
{
if (hotelSearch == null)
{
hotelSearch = new HotelSearch
{
Rooms = new List<RoomSearch> { new RoomSearch { AdultsQuantity = 1, ChildrenQuantity = 0 } },
Stars = 0,
City = "MIA",
IsoCountry = "US",
DepartureDate = Convert.ToDateTime("10/10/2013"),
ArrivalDate = Convert.ToDateTime("17/10/2013")
};
}
}
catch (Exception ex)
{
Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}
return HotelService.GetHotel(hotelSearch);
}
[HttpPost]
[HttpGet]
public Hotel GetDetails(Hotel hotel)
{
//return HotelService.GetHotelDetails(hotel);
return new Hotel();
}
关注我的 WebApiConfig:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}/",
defaults: new { id = RouteParameter.Optional }
);
}
当我尝试从 /api/Hotel/GetDetails/ 访问某些方法时,返回一条消息:“找到与请求匹配的多个操作”。
谢谢并恭祝安康。