首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Razor和Spark视图引擎的ASP.NET MVC 3

带有Razor和Spark视图引擎的ASP.NET MVC 3
EN

Stack Overflow用户
提问于 2012-06-22 06:47:47
回答 1查看 638关注 0票数 1

我最近从MVC2升级到了MVC3。我们曾经使用Spark视图引擎,而我正尝试迁移到Razor。到目前为止,升级到MVC3是成功的。我也升级了Spark视图引擎,因为我需要这样做。

问题是我能够成功地渲染Spark和Razor视图,但由于某些原因,MVC在一个位置寻找Spark文件,而在另一个位置寻找Razor文件。这就好像Razor没有正确地考虑我的领域,但Spark是。

输出:

代码语言:javascript
复制
<pre>
The view 'index' or its master was not found or no view engine supports the searched locations. The following locations were searched:

~/Areas/Live/Views/multimedia/index.aspx
~/Areas/Live/Views/multimedia/index.ascx
~/Areas/Live/Views/Shared/index.aspx
~/Areas/Live/Views/Shared/index.ascx
~/Views/multimedia/index.aspx
~/Views/multimedia/index.ascx
~/Views/Shared/index.aspx
~/Views/Shared/index.ascx
~/Areas/Live/Views/multimedia/index.cshtml
~/Areas/Live/Views/multimedia/index.vbhtml
~/Areas/Live/Views/Shared/index.cshtml
~/Areas/Live/Views/Shared/index.vbhtml
~/Views/multimedia/index.cshtml
~/Views/multimedia/index.vbhtml
~/Views/Shared/index.cshtml
~/Views/Shared/index.vbhtml
Live\~\Areas\Live\Views\multimedia\index.spark
Live\~\Areas\Live\Views\Shared\index.spark
Live\multimedia\index.spark
Live\Shared\index.spark
Live\~\Areas\Live\Views\multimedia\index.shade
Live\~\Areas\Live\Views\Shared\index.shade
Live\multimedia\index.shade
Live\Shared\index.shade
~\Areas\Live\Views\multimedia\index.spark
~\Areas\Live\Views\Shared\index.spark
multimedia\index.spark
Shared\index.spark
~\Areas\Live\Views\multimedia\index.shade
~\Areas\Live\Views\Shared\index.shade
multimedia\index.shade
Shared\index.shade
</pre>

如果我将我的.cshtml文件移动到MVC想要的位置,它将会工作,但这不会减少它。为什么这两个引擎看起来略有不同?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-12 01:28:35

根据我所读到的,Razor和Spark似乎以不同的方式寻找视图(无论如何,当使用区域时)。我不能完全确定这是否在一般情况下是正确的,或者我正在研究的实现中是否有一些不同之处。我设法通过扩展Razor引擎来解决我的问题,使其遵循与我们的项目相同的模式。

代码语言:javascript
复制
  public class CustomRazorViewEngine : RazorViewEngine
  {
      public CustomRazorViewEngine(): base()
      {
          AreaMasterLocationFormats = new string[] { "~/Areas/{2}/Views/{1}/%1/{0}.cshtml",
                             "~/Areas/{2}/Views/{1}/%1/{0}.vbhtml",
                             "~/Areas/{2}/Views/Shared/%1/{0}.cshtml",
                             "~/Areas/{2}/Views/Shared/%1/{0}.vbhtml" };

          AreaPartialViewLocationFormats = new string[] { "~/Views/{2}/Shared/{0}.cshtml" };

          AreaViewLocationFormats = new string[] { "~/Views/{2}/{1}/{0}.cshtml",
                       "~/Views/{2}/Shared/{0}.cshtml" };

          ViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml",
                       "~/Views/Shared/{0}.cshtml" };

          MasterLocationFormats = new string[] { "~/Views/{1}/%1/{0}.cshtml",
                         "~/Views/{1}/%1/{0}.vbhtml",
                         "~/Views/Shared/%1/{0}.cshtml",
                         "~/Views/Shared/%1/{0}.vbhtml" };

          PartialViewLocationFormats = new string[] { "~/Views/{1}/{0}.cshtml",
                          "~/Views/{1}/{0}.vbhtml",
                          "~/Views/Shared/{0}.cshtml",
                          "~/Views/Shared/{0}.vbhtml" };

          FileExtensions = new string[] { "cshtml", "vbhtml" };

      }

  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11147932

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档