我有两个使用相同视图的 asp.net MVC 3 Web 项目,我想将这些视图放在一个 Web 项目中,该项目包含控制器、操作过滤器、扩展方法等常见项目......(上面的项目文件夹这两个项目)。
我创建了这个自定义视图引擎来修改视图和局部视图、位置。
public class GenericViewEngine : RazorViewEngine
{
public GenericViewEngine(): this(null)
{ }
public GenericViewEngine(IViewPageActivator viewPageActivator)
{
base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/../Framework.Web/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/../Framework.Web/Views/Shared/{0}.cshtml" };
base.MasterLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/../Framework.Web/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/../Framework.Web/Views/Shared/{0}.cshtml" };
base.PartialViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml", "~/../Framework.Web/Views/{1}/{0}.cshtml", "~/Views/Shared/{0}.cshtml", "~/../Framework.Web/Views/Shared/{0}.cshtml" };
base.FileExtensions = new string[] { "cshtml" };
}
protected override IView CreatePartialView (ControllerContext controllerContext, string partialPath)
{
return base.CreatePartialView(controllerContext, partialPath);
}
protected override IView CreateView (ControllerContext controllerContext, string viewPath, string masterPath)
{
return base.CreateView(controllerContext, viewPath, masterPath);
}
}
我得到一个例外,上面写着:不能使用前导 .. 退出顶级目录。
我怎样才能把这两个项目的共同观点从每个网络项目中拿出来?是否有任何解决方案可以避免将视图编译到主要的公共 Web 项目中?
提前致谢。
何塞。