런타임에서 영역 디렉토리에서 영역을 검색하고 등록하는 플러그 가능한 ASP.NET MVC 웹 응용 프로그램에서 작업하고 있습니다.플러그 가능한 영역에 대한 면도기를 찾을 수 없음
제 문제는 뷰 엔진이 해당 영역의 뷰를 찾지 못한다는 것입니다.
: 나는 다음과 같은 오류가Html.Partial("_SearchBarPartial")
을 실행할 때
htmlHelper.ViewContext.RouteData.DataTokens["area"] = "Catalog";
을하지만 :
나는 하나의 부분보기는
내가 사용 지역을 설정~/Areas/Catalog/Views/Shared/_SearchBarPartial.cshtml
에 위치하고있다
The partial view '_SearchBarPartial' was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/Catalog/Views/Home/_SearchBarPartial.aspx ~/Areas/Catalog/Views/Home/_SearchBarPartial.ascx ~/Areas/Catalog/Views/Shared/_SearchBarPartial.aspx ~/Areas/Catalog/Views/Shared/_SearchBarPartial.ascx ~/Views/Home/_SearchBarPartial.aspx ~/Views/Home/_SearchBarPartial.ascx ~/Views/Shared/_SearchBarPartial.aspx ~/Views/Shared/_SearchBarPartial.ascx ~/Areas/Catalog/Views/Home/_SearchBarPartial.cshtml ~/Areas/Catalog/Views/Home/_SearchBarPartial.vbhtml ~/Areas/Catalog/Views/Shared/_SearchBarPartial.cshtml ~/Areas/Catalog/Views/Shared/_SearchBarPartial.vbhtml ~/Views/Home/_SearchBarPartial.cshtml ~/Views/Home/_SearchBarPartial.vbhtml ~/Views/Shared/_SearchBarPartial.cshtml ~/Views/Shared/_SearchBarPartial.vbhtml
내 폴더 구조는 다음과 같습니다
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Bootstrapper), "LoadAreas")]
public class Bootstrapper
{
public static string ModuleDirectory
{
get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Areas"); }
}
public static void LoadAreas()
{
var assemblyFiles = Directory.GetFiles(ModuleDirectory, "*.dll", SearchOption.AllDirectories);
assemblyFiles.ForEach(af =>
{
var assembly = Assembly.LoadFile(af);
if(assembly.GetTypes().Any(t => IsArea(t))
{
BuildManager.AddReferencedAssembly(assembly);
}
});
}
private static bool IsArea(Type t)
{
return typeof (AreaRegistration).IsAssignableFrom(t) && !t.IsAbstract;
}
}
Global.asax.cs
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
// ...
}
}