标准的mvc2.0程序,我要把Views文件夹改成Pages,以首页为例,
以前只要在Index方法中
return View();
即可。现在要把 return View();
改成 return View(“/Pages/Home/Index.aspx”) ;非常麻烦。
请问有没有什么方法把默认的Views改成Pages?
以前只要在Index方法中
return View();
即可。现在要把 return View();
改成 return View(“/Pages/Home/Index.aspx”) ;非常麻烦。
请问有没有什么方法把默认的Views改成Pages?
解决方案 »
- 导入Excel得到的DataTable没有像Excel文件里的行数主键,如何在导入Excel时候得到行数或者让Datatable拥有自增为1的id主键
- c# 如何把datagridview中的信息选中列所在行的信息回填到数据库中
- asp.net验证邮箱是否存在,有办法?
- 一个特别小的问题!
- 怪现象,进来帮忙找下,为什么?谢谢
- 如何实现asp.net控件数据双向绑定
- 看不懂,还请指教!!!
- 关于检验用户输入是否合法的问题
- ASP.net收邮件
- 急救!!!请问有没有免费的支持asp.net网页网站的服务器空间.
- 导出EXECL文件时如何实现进度显示
- 大家来讨论下防SQL注入的好办法,网站昨天又被黑了,第三次了,我到崩溃边缘了
修改VIewEngine就行。只是具体的不太会。我这有别人的代码,但是不想拿来用
{
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
我觉得还是不够集成。
有没有一步到位的?我的代码 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
}
运行结果
说明: HTTP 404。您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。请检查以下 URL 并确保其拼写正确。 请求的 URL: /
代码附上
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"
}}
); }