Casey Crookston
Casey Crookston

Reputation: 13955

How to make /index/ not required in the URL

I have an index page on which I need an optional parameter, so I'm doing this:

[HttpGet]
[Route("EventRegistration/Index/{status?}")]
public ActionResult Index(string status)
{
    ....
}

This works great so long as the URL is:

http://localhost:49698/EventRegistration/Index

Or

http://localhost:49698/EventRegistration/Index/something

But with this:

http://localhost:49698/EventRegistration

It throws a 404. Before adding the optional parameter, it worked fine without the `/Index'. I'd like it to keep doing so.

Thanks!

Upvotes: 0

Views: 124

Answers (1)

Casey Crookston
Casey Crookston

Reputation: 13955

This worked:

[HttpGet]
[Route("EventRegistration/Index/{status?}")]
[Route("EventRegistration")]
public ActionResult Index(string status)
{
    ....
}

Upvotes: 1

Related Questions