2013-03-04 11 views
5

NancyfxとVisual Studio 2012のRazorビューエンジンを使用して、C#でブラックジャックプログラムを作成しています。Visual StudioのIntelisenseは動作しますが、これらのRazorコンパイルエラーが発生します。私はapp/web.configの名前空間を結果なしで指定しようとしました。NancyFXを使用した面倒なコンパイルエラー

Error Details 
Error compiling template: Views/Game.cshtml 

Errors: 
[CS0246] Line: 1 Column: 11 - The type or namespace name 'Black_Jack' could not be found (are you missing a using directive or an assembly reference?) 

[CS0246] Line: 24 Column: 73 - The type or namespace name 'Black_Jack' could not be found (are you missing a using directive or an assembly reference?) 

Details: 
@using Black_Jack.Models 
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<Game> 
<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
</head> 
<body> 
    @{ 

     foreach(var player in @Model.Players.players) 
     { 
      foreach(var card in player.Hand.Cards) 
      { 
       <p>@card.Name</p> 
      } 
     } 

    } 
</body> 
</html> 

答えて

12

あなたのweb.configをもう一度見て、カミソリ設定が定義されていることを確認してください。

あなたは、以下の必要があります:それは、ここで説明されて

<configSections> 
    <section name="razor" type="Nancy.ViewEngines.Razor.RazorConfigurationSection, Nancy.ViewEngines.Razor" /> 
</configSections> 

<razor disableAutoIncludeModelNamespace="false"> 
    <assemblies> 
     <add assembly="MyAssemblyName" /> 
    </assemblies> 
    <namespaces> 
     <add namespace="Black_Jack.Models" /> 
    </namespaces> 
</razor> 

- https://github.com/NancyFx/Nancy/wiki/Razor-View-Engine

+0

感謝を!以前はリンクを見ていましたが、プロジェクト自体のアセンブリ名は含まれていません。これを追加すると別のエラーが出ました: ''System.Dynamic.ExpandoObject'型のオブジェクトを 'Black_Jack.Models.Game'と打ち込むことができません。ビューにExpandoObjectを送信しないようにコードをリファクタリングしていました。しかし、これによってweb.config内のassemblynameエントリも余計になりました。奇妙な。 –

関連する問題