使用 NancyFX 的 Razor 编译错误

标签 razor namespaces nancy

我正在使用 Nancyfx 和 Visual Studio 2012 中的 Razor View 引擎在 C# 中创建一个黑 jack 程序。Visual Studios Intelisense 工作,但我得到这些 Razor 编译错误。我尝试在 app/web.config 中指定 namespace 但没有结果。

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>

最佳答案

请再次查看您的 web.config 并确保您定义了 Razor 设置。

您将需要以下内容:

<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

关于使用 NancyFX 的 Razor 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15199555/

相关文章:

c++ - 为什么 .h 中定义的私有(private)结构需要 .cpp 文件中返回类型的作用域?

Angularjs,如何在cshtml中显示日期时间

javascript - 在 MVC 中将分部 View 渲染到布局页面的最佳方式是什么?

c# - asp.net mvc 3 Razor 和 html 表

python - 通过将属性合并/更新到模块的命名空间来加载一次配置

c# - NancyFx - Razor 编译错误

c# - 将我的 View 模型绑定(bind)到 View 会导致选中所有复选框

c++ - 类在编译时相互干扰

nancy - 在NancyFx中获取url参数

c# - 提供静态文件的 .NET Core Nancy 应用程序