Emi*_*lin 5 namespaces razor nancy
我正在使用Nancyfx和Visual Studio 2012中的Razor视图引擎在C#中创建一个黑色插孔程序.视觉工作室Intelisense可以工作,但我得到这些Razor编译错误.我已经尝试在app/web.config中指定名称空间而没有结果.
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>
Run Code Online (Sandbox Code Playgroud)
Jon*_*Jon 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>
Run Code Online (Sandbox Code Playgroud)
这里进一步解释 - https://github.com/NancyFx/Nancy/wiki/Razor-View-Engine