因此,我一直在修补我正在处理的MVC应用的视图位置,具体是因为我需要能够在子站点中为父站点使用视图/路由。自定义视图引擎位置视图模型解析问题
最终我希望能够从不同位置提供视图,比如〜/ SiteAViews/..其中〜是站点B的根目录,并且存放在站点〜/ SiteAViews /中的视图是复制到从SiteA发布构建事件。
自定义视图引擎听起来很容易。不过,我已经在自定义视图引擎(下面的示例更改)中添加了视图和母版页的位置。访问URI时发生问题,因此在SiteA dll中定义的路由(在siteB中引用)。
this.ViewLocationFormats = new string[8]
{
"~/Views/{1}/{0}.aspx",
"~/Views/{1}/{0}.ascx",
"~/Views/Shared/{0}.aspx",
"~/Views/Shared/{0}.ascx",
"~/SiteAViews/{1}/{0}.aspx",
"~/SiteAViews/{1}/{0}.ascx",
"~/SiteAViews/Shared/{0}.aspx",
"~/SiteAViews/Shared/{0}.ascx"
};
如果我改变视图引擎,和后生成任务,指/内容复制到〜/视图/站点A/..而不是〜/ SiteAViews/..这一切的伟大工程和解析视图模型。但是,〜/ SiteAViews/..我收到以下内容。
异常类型:HttpParseException异常消息:无法加载 类型 'System.Web.Mvc.ViewPage < 'Shared.MyViewModel'>'。在处System.Web.UI.TemplateParser System.Web.UI.TemplateParser.ParseFile(字符串physicalPath, VirtualPath virtualPath) System.Web.UI.TemplateParser.ParseString(字符串文本,VirtualPath virtualPath,编码fileEncoding)。解析()在 System.Web.Compilation.BaseTemplateBuildProvider.get_CodeCompilerType() 在 System.Web.Compilation.BuildProvider.GetCompilerTypeFromBuildProvider(BuildProvider buildProvider)在 System.Web.Compilation.BuildProvidersCompiler.ProcessBuildProviders() 的系统。 Web.Compilation.BuildProvidersCompiler.PerformBuild()at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath vir tualPath)
谢谢丹尼尔。很好的答案,这不用说工作。我将web.config复制到SiteAViews中,并且一切正常。我会尽全力考虑你的答案,以获得最好的,而不是最快的解决方案。我从来没有看过Views/Web.config的用途,现在我知道了。谢谢。 –
干杯蒂姆,很高兴能够帮助:) –