首页 > 解决方案 > Asp.net core 2.2 mvc 5 routing for more subfolders in Views

问题描述

I am trying to make a website application with following structure of Views:

Views
    Admin
        Player
            Index
            Create
            Update
    Client
        Index

and so on...

The issue is, how do I deal with routing since I have 2 subfolders in Views?

I tried to specify the route in the controller by:

return View("~/Views/Admin/Player/Index.cshtml");

and in the startup file:

            {
                routes.MapRoute(
                    name: "player",
                    template: "admin/Player"
                    );
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");   
            });

Sadly I cannot get to the address like https://localhost:5001/Admin/Player/ (returns a error 404)

but I get to the view by using address: https://localhost:5001/Player

Could somebody explain to me why it works like that? And how to get around it? I am tangled in that and cannot find my way out. Thank you guys!

标签: c#asp.netmodel-view-controller.net-core-2.2

解决方案


您的 admin/Player 路由未指定它将选择哪个控制器。如果您有一个名为 AdminController 的控制器和一个名为 Player 的方法,那么您的默认路由将起作用。


推荐阅读