更改视图位置 [英] Change the Views location

查看:97
本文介绍了更改视图位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中的MVC 2.0网站。我想在我的网站改变视图文件夹位置。我想保持其他文件夹里面的文件夹的意见,当我尝试这样做,我收到以下错误

I am developing a website in MVC 2.0. I want to change the View folder location in my website. I wanted to keep the views folder inside other folders, When I try to do so i am getting following errors

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 /浏览次数,而不是〜/浏览次数。请解决我的问题。我会得到什么问题,如果我更改默认的浏览文件夹位置。我是否需要更改HTML辅助类任何东西,因为我不知道在什么MVC,因为这是我开始的项目我不想risk..Please帮我...

My Views folder will be in ~/XYZ/ABC/Views instead of ~/Views. Please solve my problem. Will I get any problems If I change the default Views folder location. Do I need to change anything in HTML Helper classes because I don't know anything in MVC as this is my starting project i dont want to risk..Please help me out...

推荐答案

您需要创建,而不是一个自定义视图引擎和使用。幸运的是,你可以刚刚从默认的继承和改变构造的位置。这里有一个指导创建自己的视图引擎:的http://www.singingeels.com/Articles/Creating_a_Custom_View_Engine_in_ASPNET_MVC.aspx

You'll need to create a custom view engine and use that instead. Fortunately you can just inherit from the default one and change the locations on the constructor. Here's a guide to creating your own view engine: 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;
    }
}

这篇关于更改视图位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆