0
有沒有辦法將視圖的根文件夾更改爲bin/views文件夾?更改視圖根文件夾
有沒有辦法將視圖的根文件夾更改爲bin/views文件夾?更改視圖根文件夾
可以亞型WebFormsViewEngine:
public class MyViewEngine : WebFormViewEngine
{
public MyViewEngine() {
MasterLocationFormats = new[] {
"~/bin/Views/{1}/{0}.master",
"~/bin/Views/Shared/{0}.master"
};
ViewLocationFormats = new[] {
"~/bin/Views/{1}/{0}.aspx",
"~/bin/Views/{1}/{0}.ascx",
"~/bin/Views/Shared/{0}.aspx",
"~/bin/Views/Shared/{0}.ascx"
};
PartialViewLocationFormats = ViewLocationFormats;
}
}
然後編輯Global.asax中使用它:
private void Application_Start(object sender, EventArgs e)
{
RegisterRoutes(RouteTable.Routes);
// replace default WebForms view engine.
ViewEngines.Engines.Remove(ViewEngines.Engines.OfType<WebFormViewEngine>().Single());
ViewEngines.Engines.Add(new Namespace.MyViewEngine());
}
看起來很容易。謝謝 :) – 2009-05-28 15:18:39