标准的mvc2.0程序,我要把Views文件夹改成Pages,以首页为例,
以前只要在Index方法中
return View();
即可。现在要把 return View();
改成 return View(“/Pages/Home/Index.aspx”) ;非常麻烦。
请问有没有什么方法把默认的Views改成Pages?

解决方案 »

  1.   

    改得了。我就是不是很清楚怎么改。
    修改VIewEngine就行。只是具体的不太会。我这有别人的代码,但是不想拿来用
      

  2.   

    你敢吧项目结构截图发上来么?好好看看是不是标准的MVC项目
      

  3.   

    在Web项目中一样可以使用路由,如果你想自定义你的项目结构,完全可以写一个属于自己的MVC框架
      

  4.   

    可以改        public static void AddViewEngine()
            {
                ViewEngines.Engines.Add(new WebFormViewEngine()
                {
                    MasterLocationFormats = new string[] {
                "~/Pages/{1}/{0}.master",
                "~/Pages/Shared/{0}.master"
            },
                    ViewLocationFormats = new string[] {
                "~/Pages/{1}/{0}.aspx",
                "~/Pages/{1}/{0}.ascx",
                "~/Pages/Shared/{0}.aspx",
                "~/Pages/Shared/{0}.ascx"
            },
                    PartialViewLocationFormats = new string[] {
                "~/Pages/{1}/{0}.aspx",
                "~/Pages/{1}/{0}.ascx",
                "~/Pages/Shared/{0}.aspx",
                "~/Pages/Shared/{0}.ascx"
            }
                }
    );            
            }
    在 Application_Start 里调用 AddViewEngine
      

  5.   

    先谢谢大家抽时间帮忙。6楼的是张子秋的mvc教程吧?可是光是那样的话我要是以后想自定义皮肤怎么办?
    我觉得还是不够集成。
    有没有一步到位的?我的代码 public class GLViewEngine :IViewEngine
        {
            #region IViewEngine 成员        public ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
            {
                return FindView(controllerContext, partialViewName, null, useCache);
            }        public ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
            {
                if (controllerContext == null)
                    throw new ArgumentNullException("controllerContext is required.", "controllerContext");
                if (string.IsNullOrEmpty(viewName))
                    throw new ArgumentException("viewName is required.", "viewName");
                ////当前不允许在Controller中指定View的masterName
                //if (!string.IsNullOrEmpty(masterName))
                //{
                //    throw new ArgumentException("不允许在Controller中指定View的masterName", "masterName");
                //}                        //如果是新加入的页面。就不走皮肤了。
                if (viewName.ToLower().StartsWith("mypage"))
                {
                    string viewpath = @"~/" + viewName;
                    string mastername = masterName;
                    if (!string.IsNullOrEmpty(masterName))
                    {
                        mastername = @"~/" + masterName;
                    }                return new ViewEngineResult(new WebFormView(viewpath, mastername), this);
                }
                string actualViewPath = "~/Pages";            string actualMasterPath = "~/Pages";
                return new ViewEngineResult(new WebFormView(actualViewPath, actualMasterPath), this);        }        public void ReleaseView(ControllerContext controllerContext, IView view)
            {
                IDisposable disposable = view as IDisposable;
                if (disposable != null)
                    disposable.Dispose();
            }        #endregion
        }
      

  6.   

    对了。上面的代码是不正确的。
    运行结果
    说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。 请求的 URL: /
      

  7.   


    代码附上
    protected void Application_Start()
            {
                //ViewEngines.Engines.Clear();
                //ViewEngines.Engines.Add(new GLViewEngine());
                AddViewEngine();
                AreaRegistration.RegisterAllAreas();            RegisterRoutes(RouteTable.Routes);
            }        protected void AddViewEngine()
            {
                ViewEngines.Engines.Add(new WebFormViewEngine()
                {
                    MasterLocationFormats = new string[] {
                "~/Pages/{1}/{0}.master",
                "~/Pages/Shared/{0}.master"
                },
                    ViewLocationFormats = new string[] {
                "~/Pages/{1}/{0}.aspx",
                "~/Pages/{1}/{0}.ascx",
                "~/Pages/Shared/{0}.aspx",
                "~/Pages/Shared/{0}.ascx"
                },
                    PartialViewLocationFormats = new string[] {
                "~/Pages/{1}/{0}.aspx",
                "~/Pages/{1}/{0}.ascx",
                "~/Pages/Shared/{0}.aspx",
                "~/Pages/Shared/{0}.ascx"
                }}
                );        }