Manguera v
Manguera v

Reputation: 482

How do i change startup url path of Razor Page Application so it can load a specific .cshtml

I want to load my application at http://localhost:52856/CRUD/Products/List so then i can start working on the List.cshtml file instead of loading Index.cshtml at http://localhost:52856 .
Look i know i can just put a button at the index file so then it can redirect to path or use the navbar, but personally i don't want to do that every single time.Just load the application at the file.cshtml i want. But How can i do it?

Upvotes: 0

Views: 1600

Answers (2)

Michael Wang
Michael Wang

Reputation: 4022

1. Include MVC as a service into our app. we can optionally use another method called AddRazorPagesOptions() like so:

services.AddMvc().AddRazorPagesOptions(options =>
        {
            options.Conventions.AddPageRoute("/Customer/Index", "");
        });

Within that AddRazorPagesOptions() method, we can set things like route conventions and the root directory for pages. It turns out that, to set a default route for a page.

2. remove or rename Pages/Index.cshtml

Upvotes: 1

Joe Smith
Joe Smith

Reputation: 127

If you don't like my comment you could do the following in Index.cshtml.cs

public IActionResult OnGet()
{
    return new RedirectToPageResult("/CRUD/Product/List");
}

Upvotes: 1

Related Questions