A real head-scrather this one. I have created two ApiControllers which I am using as a JSON webservice:-
一个真正令人头疼的问题。我创建了两个ApiControllers,我将其用作JSON Web服务: -
namespace ControlTower.Controllers
{
public class AirlinesController : ApiController
{
private static IEnumerable<Airline> MapAirlines()
{
return (Jetstream.AirlineObject.GetAirlines()).Select(x => x);
}
[HttpGet]
public IEnumerable<Airline> GetAirlines()
{
return MapAirlines().AsEnumerable();
}
[HttpGet]
public Airline GetAirlineByCode(string code)
{
return Jetstream.AirlineObject.GetAirline(code);
}
}
}
and:-
和:-
namespace ControlTower.Controllers
{
public class ReviewsController : ApiController
{
private static IEnumerable<Review> MapReviews(int airline)
{
return (Jetstream.ReviewObject.GetReviews(airline)).Select(x => x);
}
[HttpGet]
public IEnumerable<Review> GetReviews(int airline)
{
return MapReviews(airline).AsEnumerable();
}
[HttpGet]
public Review GetReviewById(int review)
{
return Jetstream.ReviewObject.GetReview(review);
}
}
}
With this routing:-
有了这个路由: -
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/get/{code}",
defaults: new { code = RouteParameter.Optional }
);
And whilst visiting /api/airline/get/ba
or /api/airline/get/
works perfectly, visiting any variation of Review does not. Can anyone see anything really obvious I'm missing here?
在访问/ api / airline / get / ba或/ api / airline / get / works时,访问任何Review的变体都没有。任何人都可以看到任何非常明显的东西吗?
Help is appreciated.
感谢帮助。
1 个解决方案
#1
18
Your default route is expecting a parameter named "code". You either need to add a route to accept a parameter named airline and/or review, or explicitly tell the controller the name of the parameter.
您的默认路由期望一个名为“code”的参数。您需要添加路由以接受名为airline和/或review的参数,或者明确告诉控制器参数的名称。
ex. /api/reviews/get?airline=1
恩。 / API /评论/获取?航空公司= 1
#1
18
Your default route is expecting a parameter named "code". You either need to add a route to accept a parameter named airline and/or review, or explicitly tell the controller the name of the parameter.
您的默认路由期望一个名为“code”的参数。您需要添加路由以接受名为airline和/或review的参数,或者明确告诉控制器参数的名称。
ex. /api/reviews/get?airline=1
恩。 / API /评论/获取?航空公司= 1