简体   繁体   English

将所有视图放入MVC中的一个视图子文件夹

[英]Put all the view into one view sub folder in MVC

I'm a very beginner(Learner) in MVC. 我是MVC的初学者(学习者)。 Is this question is stupid, sorry for that. 这个问题是愚蠢的,对此感到抱歉。 I'm having three controllers 我有三个控制器

  • Home
  • Main_Menu 主菜单
  • Booking 订票

Added view for this controller and its having three sub folder views 添加了此控制器的视图及其三个子文件夹视图

  • View/Home/Home.cshtml 查看/首页/Home.cshtml
  • View/Main_Menu/Main_Menu.cshtml 查看/Main_Menu/Main_Menu.cshtml
  • View/Booking/Booking.cshtml 查看/预订/Booking.cshtml

Is it possible to put all view into one sub folder like this 是否可以将所有视图放入这样的一个子文件夹中

  • View/Home/Home.cshtml 查看/首页/Home.cshtml
  • View/Home/Main_Menu.cshtml 查看/首页/Main_Menu.cshtml
  • View/Home/Booking.cshtml 查看/首页/Booking.cshtml

Is this stupid? 这是愚蠢的吗? Is this bad approach? 这是不好的方法吗?

ASP.NET MVC already have such all in one folder - Views/Shared ASP.NET MVC已经在一个文件夹中包含所有这些内容- Views/Shared

If you put your view there and call Controller , that don't have View in it's own folder you get the View from Shared . 如果您将视图放在此处并调用Controller ,而该Controller在其自己的文件夹中没有View ,则会从Shared获取View

Also, you can try to change View location by creating Custom View Engine but it's not so easy. 另外,您可以尝试通过创建“自定义视图引擎”来更改“视图”位置,但这并不容易。 You can find how to do it here . 您可以在这里找到操作方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM