How to use an Area in ASP.NET Core

前端 未结 8 753
[愿得一人]
[愿得一人] 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:09

    Use this pattern in Configure method in Startup.Cs, as its full routing manner:

    app.UseMvc(routes =>{
       routes.MapRoute(
       name: "MyArea",
       template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
    
    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");});
    

    In Core 3.1 you should use below code in ConfigureServices method:

    services.AddMvc(option => option.EnableEndpointRouting = false);
    

提交回复
热议问题