asp.net-mvc ASP.NET MVC 如何指定视图页面所在的文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/799838/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-07 23:33:00  来源:igfitidea点击:

ASP.NET MVC How to specify which folder the View pages reside in?

asp.net-mvcnamespaces

提问by Ropstah

by default the ASP.NET MVC engine searches the following folders for View pages:

默认情况下,ASP.NET MVC 引擎会在以下文件夹中搜索查看页面:

  • /Views/{Controller_Name}/{Action}.aspx
  • /Views/Shared/{Action}.aspx
  • /Views/ {Controller_Name}/{Action}.aspx
  • /Views/共享/{Action}.aspx

However I want to put some of my View pages like this:

但是我想把我的一些视图页面像这样:

  • /Views/{Namespace}/{Controller_Name}/{Action}.aspx
  • /Views/ {Namespace}/{Controller_Name}/{Action}.aspx

How can I let the engine look for this?

我怎样才能让引擎找到这个?

采纳答案by Ofigenn

You have to create a class derived from IViewEngine interface and register this class in Aplication_Start event in Global.asax.cs Check this link text, but there are some differences with 1.0

你必须创建一个派生自IViewEngine接口的类并在Global.asax.cs的Aplication_Start事件中注册这个类查看这个链接文本,但与1.0有一些差异

回答by Kailas Mane

You can return view placed in custom sub-folders, from controller action by, giving out full view path in return statement,

您可以返回放置在自定义子文件夹中的视图,从控制器操作通过,在返回语句中给出完整的视图路径,

ex.

前任。

public ActionResult Create()
{
    return View("~/Views/ProEnhance/Employee/Create.cshtml");
}

here,

这里,

ProEnhance - user defined folder

ProEnhance - 用户定义的文件夹

Employee - Controller Name

员工 - 控制人姓名

Create - action Name

创建 - 操作名称