I am trying to create a nested route for one of my controllers.
I have tried this:
RouteConfig:
routes.MapHttpRoute(
name: "InhabsApi",
routeTemplate: "api/rooms/{id}/inhabitants/{inhabid}",
defaults: new { inhabid = RouteParameter.Optional });
Controller looks like this:
[Abp.WebApi.Authorization.AbpApiAuthorize]
public IHttpActionResult Get(long id)
{
return Ok(_roomService.GetAllInhabs(id));
}
Unfortunatelly it does not work. I read Attribute Routing could help, but I am not sure if this works with Abp. Any help would be very appreciated :)
4 Answer(s)
-
0
It did help to specify the controller in the route:
routes.MapHttpRoute( name: "InhabsApi", routeTemplate: "api/rooms/{id}/inhabitants/{inhabid}", defaults: new { controller = "Inhabitants", inhabid = RouteParameter.Optional });
Problem solved. But anyways, what do you think about Attribute Routing?
-
0
I can't get this to work with PUT
It works with GET and POST though....
not sure, what the problem is
-
0
It seems related to Web API, not ABP. Because ABP has nothing to prevent it as I know. Is same code working in another project without ABP?
-
0
It works! Finally got it working.
It was a rather stupid mistake, which i did oversee. I use Postman (chrome plugin) for testing and did provide a Content-Type = application/javascript instead of application/json
The answer is: Use Content-Type = application/json This works, thank you for your answer!