2013-03-04 62 views
5

我使用Nancyfx和Visual Studio 2012中的Razor視圖引擎在C#中創建黑色插孔程序。Visual Studio工作室Intelisense可以工作,但是我得到了這些Razor編譯錯誤。我已經嘗試在app/web.config中指定名稱空間,但沒有結果。使用NancyFX的Razor編譯錯誤

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條目變得多餘。奇怪的。 – 2013-03-05 13:46:27