How to use an Area in ASP.NET Core

前端 未结 8 739
[愿得一人]
[愿得一人] 2020-11-28 23:45

How do I use an Area in ASP.NET Core?

I have an app that needs an Admin section. This section requires its Views to be placed in that area. All request

8条回答
  •  渐次进展
    2020-11-29 00:05

    In ASP.NET Core 3.0. If you are working with Endpoint patterns, after adding the Area (Right click over project, Add, New Scaffolded Item, Area), you have to add manually routing pattern on startup.cs Configure method. (At this point the generated ScaffoldingReadMe.txt is out of date).

    app.UseEndpoints(endpoints =>
    {
    
        endpoints.MapAreaControllerRoute(
            "Admin",
            "Admin",
            "Admin/{controller=Home}/{action=Index}/{id?}");
    
        endpoints.MapControllerRoute(
             name: "default",
             pattern: "{controller=Home}/{action=Index}/{id?}");
    });
    

提交回复
热议问题