i would like to create rest api but I have problem with routing.
This url is ok: localhost/project/controller/action/id, but i would like this url localhost/project/controller/id too.
For example: localhost/project/article/5: ArticleController.Get(int id)
This is my code:
Project controller
[HttpGet]
[Route("project/{id}")]
public JsonResult Get(int id)
{
}
Route config:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Api",
url: "{controller}/{id}",
defaults: new { id = UrlParameter.Optional }
);
}
When i call url localhost/project/article/5, error message is A public action method '5' was not found on controller 'ArticleController'.
Where is problem? Thanks