How to use an Area in ASP.NET Core

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

    With .net core, following is needed to be added in the startup file if you are adding an area:
    
         app.UseMvc(routes =>
                {
                    routes.MapRoute(
                      name: "areas",
                      template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
                    );
                });
    
    After that you can just simply mark your area and route in the controller, i.e
         [Area("Order")]
         [Route("order")]
    

    it works for me.

提交回复
热议问题