熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

Asp.Net Mvc3 修改視圖的默認路徑

2022-06-13   來源: .NET編程 
    [csharp]
   
    public class StructRazorViewEngine : RazorViewEngine
   
    {
   
    public StructRazorViewEngine()
   
    : base()
   
    {
   
    //Area視圖路徑其中{}{}{}分別代表Area名Controller名Action名
   
    AreaViewLocationFormats = new[] { ~/{}/{}/{}cshtml ~/Shared/{}cshtml };
   
    //Area模版路徑
   
    AreaMasterLocationFormats = new[] { ~/Shared/{}cshtml };
   
    //Area的分部視圖路徑
   
    AreaPartialViewLocationFormats = new[] { ~/{}/{}/{}cshtml ~/Shared/{}cshtml };
   
    //主視圖路徑
   
    ViewLocationFormats = new[] { ~/{}/{}cshtml ~/Shared/{}cshtml };
   
    //主模版路徑
   
    MasterLocationFormats = new[] { ~/Shared/{}cshtml };
   
    //主分部視圖路徑
   
    PartialViewLocationFormats = new[] { ~/{}/{}cshtml ~/Shared/{}cshtml };
   
    }
   
    protected override IView CreatePartialView(ControllerContext controllerContext string partialPath)
   
    {
   
    return baseCreatePartialView(controllerContext partialPath)
   
    }
   
    protected override IView CreateView(ControllerContext controllerContext string viewPath string masterPath)
   
    {
   
    return baseCreateView(controllerContext viewPath masterPath)
   
    }
   
    protected override bool FileExists(ControllerContext controllerContext string virtualPath)
   
    {
   
    return baseFileExists(controllerContext virtualPath)
   
    }
   
    }
From:http://tw.wingwit.com/Article/program/net/201311/13965.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.