2012-06-21 161 views
1

我最近從MVC2升級到MVC3。我們曾經使用Spark視圖引擎,並試圖開始遷移到Razor。到目前爲止,升級到MVC3是成功的。我也升級了Spark視圖引擎,因爲我需要。ASP.NET MVC 3與Razor和Spark視圖引擎並列

問題是我能夠成功渲染Spark和Razor視圖,但由於某種原因,MVC正在尋找一個位置的Spark文件和另一個位置的Razor。就好像剃刀不是正確地考慮我的領域,但Spark是。

輸出:

<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希望它是它會工作但是這不會削減它。爲什麼這兩款發動機的外觀稍有不同?

回答

0

從我讀過的書中看來,Razor和Spark似乎以不同的方式尋找視圖(無論如何使用區域)。我不完全確定這是否是真的,或者如果我正在處理的這個實現有些不同。我設法通過擴展Razor引擎來遵循我們項目的相同模式來解決我的問題。

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" }; 

     } 

    }