0
votes

I have an MVC app to which I am trying to add some Razor pages. I have added the following page to the project root:

pages/account/index.cshtml

However I am unable to generate a URL to this page using the tag helpers like this:

<a  class="nav-link text-dark"  asp-page="/Account" title="Manage">Hello @User.Identity.Name!</a>

This results in this url: /Asset/List?page=%2FAccount%2FAccount

Which is a url relative to the current page.

However I am unable to browse to /account/index or /account in the browser, which tells me something is up with the routing.

My MVC controller routes are working fine, as are the default Razor pages created in the project template in the identity area, for example:

identity/pages/account/manage/index

My configure method looks like this:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseDatabaseErrorPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }
        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapRazorPages();
        });
    }

and ConfigureServices:

public void ConfigureServices(IServiceCollection services)
        {
            
            services.AddControllersWithViews().AddRazorRuntimeCompilation();
            services.AddRazorPages();
        }
1

1 Answers

1
votes

I have an MVC app to which I am trying to add some Razor pages. I have added the following page to the project root:

pages/account/index.cshtml

That will result in a route being generated of /account/. The value passed to the asp-page attribute is the relative file path (rooted in the Pages folder) without the extension:

<a asp-page="/account/index">Account Home </a>

More about routing in Razor Pages here: https://www.learnrazorpages.com/razor-pages/routing