MVCビューのデフォルトパスの変更
4396 ワード
1、RazorViewEngineから受け継いだクラスを作成し、ビューパスを書き換える
2、アプリケーション_Start()に文を追加します.
//ビュールールの登録RegisterView(ViewEngines.Engines);
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、アプリケーション_Start()に文を追加します.
//ビュールールの登録RegisterView(ViewEngines.Engines);