Skip to content

Strongly typed @page route in Razor Pages #8065

Closed

Description

@Ponant

On a razor page we can do this to change the default folder-based route:
@page "/xxx/yyy"

but trying to do this with a strongly typed property in some class Constants.Routes does not work
public const string Myroute = "/mysuperroute";
and
@page @Constants.Routes.Myroute

I am getting an error The 'page' directive expects a string surrounded by double quotes.

Is there a way around this? I would like to avoid route duplication through the options
e.g. https://docs.microsoft.com/en-us/aspnet/core/razor-pages/razor-pages-conventions?view=aspnetcore-2.2#configure-a-page-route
Thanks

Activity

  1. added
    area-mvc
    on Mar 1, 2019
  2. added
    ✔️ Resolution: By Design
    on Mar 1, 2019
  3. NTaylorMullen commented on Mar 1, 2019

    @NTaylorMullen

    @Ponant sadly there is no way around this and is by design due to our requirement to harvest page routes without needing to run the application or do C# advanced logic to determine what a pages route should be.

  4. Ponant commented on Mar 16, 2019

    @Ponant
    ContributorAuthor

    @NTaylorMullen , I understand but I think it will be a big plus because I find it very hard to scale an app with strings.

  5. ghost locked as resolved and limited conversation to collaborators on Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: By Designarea-mvc

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions