question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple Routes For a Razor Page

See original GitHub issue

Razor Pages Feature Request

Asp.Net MVC supports multiple routes per action:

[Route("something/{id}")]
[Route("somethingelse/{id}")]
public ActionResult Index(int id)

I would love the ability for Razor Pages to support something like this at the page level. Something like:

@page {"something/{id}","somethingelse/{id}"}

Or support adding Route attributes to PageModels?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pranavkmcommented, Jun 6, 2019

Using AddPageRoute makes it the default route for link generation. Essentially any other route associated with that page do not participate in link generation. There’s a bug in MVC where calling AddPageRoute multiple times prevents previously added route from being used for link generation. That said, you could write a convention that configures the routes for the page. Here’s what the AddPageRoute does under the hood:

https://github.com/aspnet/AspNetCore/blob/b93bc433db66175d2b07b128ec9990f7a4dd7e1b/src/Mvc/Mvc.RazorPages/src/DependencyInjection/PageConventionCollectionExtensions.cs#L470-L490

0reactions
mxmissilecommented, May 31, 2019

I have a scenario where I cannot get that to work:

Page: Pages/Production/details.cshtml @page directive is blank

Added this convention:
options.Conventions.AddPageRoute("/production/details", "production/{id}/details");

In the browser: "/production/details" works "/production/100/details" works

The issue is with tag helpers: <a asp-page="/production/details" asp-route-id="100"> works <a asp-page="/production/details"> blank href

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple routes to the same razor page
I've got a razor page in my Asp.Net Core 3.1 website called SignupAndApply. It's effectively a copy and paste of the register identity...
Read more >
Routing in Razor Pages
Routing is the system that matches URLs to Razor pages. Like most page-centric frameworks, the primary routing system in ASP.NET Razor Pages ......
Read more >
Multiple Routes For a Razor Page · Issue #10691
Razor Pages Feature Request Asp.Net MVC supports multiple routes per action: [Route("something/{id}")] [Route("somethingelse/{id}")] public ...
Read more >
Razor Pages route and app conventions in ASP.NET Core
Learn how to use page route and app model provider conventions to control page routing, discovery, and processing in Razor Pages apps.
Read more >
5 Mapping URLs to Razor Pages using routing
Routing is the process of mapping an incoming request URL to a Razor Page that will execute to generate a response. You can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found