TL;DR;
How can i have "http://localhost/posts/1" be routed to public IActionResult Index(int? id)
on PostsController?
Semi-Long Version:
My routes are defined as:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "posts",
template: "Posts/{id:int?}",
defaults: new { controller = "Posts", action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id:int?}");
});
my posts controller is:
[Route("posts")]
public class PostsController : Controller
{
public IActionResult Index(int? id)
{
return View();
}
}
the problem is that "http://localhost:5432/posts" works ok BUT "http://localhost:5432/posts/1" does route properly...
Edit1:
public class PostsController : Controller
{
[Route("Posts/{id:int?}"
public IActionResult Index(int? id)
{
return View();
}
}
works... but i would not like to have routes handled for each action... this is supposed to be a very large system... things might get crazy like this...
int
constraint – Leonardo