Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core Razor Pages with Multiple Routes

How do I configure my razor page to accept multiple routes? For example, if I have a razor page ./Pages/Inovices/Overview.cshtml. I need this page to handle requests for ~/invoices AND ~/invoices/overview. Currently I'm using Handler methods on an Index.cshtml but it feels like there should be an easier way. Any thoughts?

like image 398
lestersconyers Avatar asked Aug 30 '25 16:08

lestersconyers


1 Answers

You can add a convention for your page, using AddPageRoute. Here's what it would look like for your example:

services.AddMvc(...)
    .AddRazorPagesOptions(options =>
    {
        options.Conventions.AddPageRoute("/Invoices/Overview", "invoices");
    });

This adds a new route for the page but also keeps the existing route as is.

like image 158
Kirk Larkin Avatar answered Sep 02 '25 23:09

Kirk Larkin