asp.net – 更改视图位置

我正在开发一个MVC 2.0的网站.我想更改我网站中的View文件夹位置.我想将views文件夹保存在其他文件夹中,当我尝试这样做时,我遇到了以下错误
The view 'Index' or its master was not found. The following locations were searched:
~/Views/Search/Index.aspx
~/Views/Search/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

我的视图文件夹将在〜/ XYZ / ABC / Views中,而不是〜/ Views.请解决我的问题.我是否会遇到任何问题如果我更改认的Views文件夹位置.我是否需要更改HTML Helper类中的任何内容,因为我对MVC一无所知,因为这是我的开始项目,我不想冒险…请帮帮我…

解决方法

您需要创建一个自定义视图引擎并使用它.幸运的是,您可以从认值继承并更改构造函数上的位置.以下是创建自己的视图引擎的指南: http://www.singingeels.com/Articles/Creating_a_Custom_View_Engine_in_ASPNET_MVC.aspx

来自文章

protected void Application_Start()
{
    //... other things up here.

    // I want to REMOVE the ASP.NET ViewEngine...
    ViewEngines.Engines.Clear();

    // and then add my own :)
    ViewEngines.Engines.Add(new HoTMeaTViewEngine());
}

public class HoTMeaTViewEngine : VirtualPathProviderViewEngine
{
    public HoTMeaTViewEngine()
    {
        // This is where we tell MVC where to look for our files. This says
        // to look for a file at "Views/Controller/Action.html"
        base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.html" };

        base.PartialViewLocationFormats = base.ViewLocationFormats;
    }
}

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....