Back
Theme:

Have you already used AddPageRoute on Razor?


Have you already used AddPageRoute on Razor?

Date: Thursday, July 6, 2023
1 answers | 366 view(s)
by Mauricio Junior

Answers

You can configure it on public void ConfigureServices(IServiceCollection services) in your API. After that, you can use a convention to add a page route.

For example:

services.AddRazorPages()
        .AddRazorPagesOptions(options =>
        {
            options.Conventions.AddPageRoute("/student/video", "/student/video/{id?}/{text?}/course/{courseId?}");
        });
}

It means, the page of the user will access is /student/video but the address will be /student/video/{id}/text/course/courseid. You need to get the values using RouteData.Values["id"]; and more.

I hope I help you with this example.

Thursday, July 6, 2023

Mauricio Junior


25