Cuối cùng tôi đã kiểm tra, điều này đòi hỏi bạn phải xây dựng ViewEngine của riêng bạn. Tôi không biết nếu họ làm cho nó dễ dàng hơn trong RC1 mặc dù.
Cách tiếp cận cơ bản mà tôi đã sử dụng trước RC đầu tiên là trong ViewEngine của riêng tôi, để tách không gian tên của bộ điều khiển và tìm các thư mục khớp với các phần.
EDIT:
Went trở lại và tìm thấy mã. Đây là ý tưởng chung.
public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName)
{
string ns = controllerContext.Controller.GetType().Namespace;
string controller = controllerContext.Controller.GetType().Name.Replace("Controller", "");
//try to find the view
string rel = "~/Views/" +
(
ns == baseControllerNamespace ? "" :
ns.Substring(baseControllerNamespace.Length + 1).Replace(".", "/") + "/"
)
+ controller;
string[] pathsToSearch = new string[]{
rel+"/"+viewName+".aspx",
rel+"/"+viewName+".ascx"
};
string viewPath = null;
foreach (var path in pathsToSearch)
{
if (this.VirtualPathProvider.FileExists(path))
{
viewPath = path;
break;
}
}
if (viewPath != null)
{
string masterPath = null;
//try find the master
if (!string.IsNullOrEmpty(masterName))
{
string[] masterPathsToSearch = new string[]{
rel+"/"+masterName+".master",
"~/Views/"+ controller +"/"+ masterName+".master",
"~/Views/Shared/"+ masterName+".master"
};
foreach (var path in masterPathsToSearch)
{
if (this.VirtualPathProvider.FileExists(path))
{
masterPath = path;
break;
}
}
}
if (string.IsNullOrEmpty(masterName) || masterPath != null)
{
return new ViewEngineResult(
this.CreateView(controllerContext, viewPath, masterPath), this);
}
}
//try default implementation
var result = base.FindView(controllerContext, viewName, masterName);
if (result.View == null)
{
//add the location searched
return new ViewEngineResult(pathsToSearch);
}
return result;
}
Dưới đây là một mẫu của một ViewEngine đơn giản từ ứng dụng MVC Thương mại Rob Connery: [View Engine Mã] (http://mvcsamples.codeplex.com/SourceControl/changeset/view/17126#286681) Và mã Global.asax.cs để đặt ViewEngine: [Global.asax.cs] (http: //mvcsamples.codeplex. com/SourceControl/changeset/view/17126 # 286569) Hy vọng điều này sẽ giúp. –