asp.net - 更改 View 位置

标签 asp.net asp.net-mvc asp.net-mvc-2

我正在使用 MVC 2.0 开发一个网站。我想更改我网站中的查看文件夹位置。我想将 View 文件夹保留在其他文件夹中,当我尝试这样做时,我遇到了以下错误

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.

我的 View 文件夹将位于 ~/XYZ/ABC/Views 而不是 ~/Views。请解决我的问题。如果我更改默认的 Views 文件夹位置,我会遇到任何问题。我是否需要更改 HTML Helper 类中的任何内容,因为我不知道 MVC 中的任何内容,因为这是我不想冒险的开始项目..请帮助我...

最佳答案

您需要创建一个自定义 View 引擎并改用它。幸运的是,您可以从默认继承并更改构造函数上的位置。以下是创建您自己的 View 引擎的指南: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;
    }
}

关于asp.net - 更改 View 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2735240/

相关文章:

c# - 如何将新创建的用户登录到站点

css - 如何在 <td> 的工具提示中添加 <br>

asp.net-mvc - 更新网站时处理404

asp.net-mvc - ASP.NET MVC : RenderPartial for a static HTML file

asp.net-mvc-2 - MVC 2,将模型显示为文本框

javascript - 使用javascript将值从td分配给asp.net hiddenfield

asp.net - Web.config 和 MySQL 问题。

asp.net-mvc - Breeze ,创建实体

c# - 使用 LINQ 表达式的文本表示

asp.net - 在 ASP.Net MVC 中访问 "Application"对象以存储应用程序范围的变量