1

最近、MVC2からMVC3にアップグレードしました。以前はSparkビューエンジンを使用していましたが、Razorへの移行を開始しようとしています。これまでのところ、MVC3へのアップグレードは成功しました。必要だったので、Sparkビューエンジンもアップグレードしました。

問題は、SparkビューとRazorビューの両方を正常にレンダリングできることですが、何らかの理由で、MVCはある場所でSparkファイルを探し、別の場所でRazorを探しています。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が望む場所に移動すると、それは機能しますが、それはそれをカットしません。2つのエンジンがわずかに異なる場所を探しているのはなぜですか?

4

1 に答える 1

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

      }

  }
于 2012-07-11T17:28:35.150 に答える