c# - 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!
解决方案
您的 admin/Player 路由未指定它将选择哪个控制器。如果您有一个名为 AdminController 的控制器和一个名为 Player 的方法,那么您的默认路由将起作用。
推荐阅读
- android - android studio 3.6 如何离线设置gradle
- scala - Scala spark 将数据框中的一组列聚合为 JSON 字符串
- java - 为什么 Java Unsafe CAS (getAndAddInt) 比手动编写的代码快
- angular - 从父输入到子输入的原始布尔类型的角度切换 NgOnChanges
- dart - dart 是否允许用户编写特定于平台的实现?
- java - 如何使用 Akka 以分块方式从 Oracle 表中获取记录?
- html - 我只得到引导程序下拉列表中前两个字符的底线
- python - 找到最小张量值的 p% - TensorFlow 2.0
- flutter - Flutter TextField TextFieldController setState - 光标位置变化
- html - Css Grid 不能影响输入项