0

I have the following code in my Startup.cs

endpoints.MapControllerRoute(
                    name: "Default",
                    pattern: "{controller}/{action}/{id?}"
                );

Routing doesn't work for the following method in the controller and returns 404

public async Task<ActionResult> Index(int id)
{
}

The url I'm trying to navigate is

/home/our-villages/property/100

However, it's working fine without the parameter value '100'. It hits the controller action in this case.

/home/our-villages/property

I believe I'm missing something in reagards to setting up the routing with parameters here. Any idea?

chamara
  • 12,649
  • 32
  • 134
  • 210

1 Answers1

0

Have you tried making the id parameter for the method optional?

Try doing this

public async Task<ActionResult> Index(int id = 0)
{
}

or

public async Task<ActionResult> Index(int? id)
{
}
liamgold
  • 288
  • 1
  • 9