首页 > Web开发 > 详细

MVC修改视图的默认路径

时间:2015-06-12 19:04:58      阅读:305      评论:0      收藏:0      [点我收藏+]

1、编写继承自RazorViewEngine的类,重写视图路径

 1   public class ViewEngine : RazorViewEngine
 2     {
 3          /// <summary>
 4         /// Initializes a new instance of the <see cref="ViewEngine"/> class.
 5         /// </summary>
 6         public ViewEngine()
 7          {
 8             var views = new[]
 9             {
10                 "~/Views/{1}/{0}.cshtml",
11                 "~/Views/Shared/{0}.cshtml",
12                 "~/Views/Base/{0}.cshtml",
13                 "~/Views/Base/{1}/{0}.cshtml",
14             };
15 
16             this.PartialViewLocationFormats = views;
17 
18             this.ViewLocationFormats = views;
19         }
20 
21         /// <summary>
22         /// 添加视图规则
23         /// </summary>
24         /// <param name="viewEngineCollection">viewEngineCollection</param>
25         internal static void RegisterView(ViewEngineCollection viewEngineCollection)
26         {
27             viewEngineCollection.Add(new ViewEngine());
28         }

2、在Application_Start()中添加语句:

// 注册视图规则
ViewEngine.RegisterView(ViewEngines.Engines);

 

MVC修改视图的默认路径

原文:http://www.cnblogs.com/liuxiaoji/p/4571995.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!