razor - (Nancy) Razor View Engine 部分 View 渲染完整 HTML

标签 razor partial-views nancy

使用 Nancy 和 Razor View 引擎,我得到以下情况。 我有一个看法:

@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>
        @Html.Partial("_PartialPage1")
    </body>
</html>

部分 View 包含:

   <strong>I am partial.</strong>

运行应用程序后生成的 HTML 看起来像这样

<!DOCTYPE html>
<html>
    <head>
        <title></title>

    </head>
    <body>
        <div>
    <!DOCTYPE html>
<html>
    <head>
        <title></title>

    </head>
    <body>


<strong>I am partial.</strong>

</body>
</html>

</div>
    </body>
</html>

看起来好像部分内容被呈现为完整的 HTML 页面而不是片段。有谁知道如何解决这个问题吗?

编辑:我正在使用 Nancy.Hosting.Aspnet。

更新:我正在使用 _ViewStart.cshtml,它似乎也适用于部分 View 。这可以预防吗?

更新: View 文件夹中的文件

Views
  Default
    _ViewStart.cshtml
    Index.cshtml
  Partials
    _PartialPage.cshtml
  Shared
    _LayoutPage.cshtml

_ViewStart.cshtml 包含对要使用的布局页面的引用。

@{
  Layout = "Views/Shared/_LayoutPage.cshtml";
}

问题是它也适用于 _PartialPage.cshtml。与 _ViewStart.cshtml 放置在哪个文件夹无关。 我希望你能像这样重现它。

最佳答案

简而言之,当使用 Nancy/Razor de _ViewStart.cshtml 时,它会应用于所有 View ,甚至是部分 View 。 感谢菲尔澄清了这一点。

关于razor - (Nancy) Razor View Engine 部分 View 渲染完整 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19957737/

相关文章:

asp.net-mvc-2 - 为什么 ValidationMessageFor 在这种情况下不显示我的验证消息?

linux - 如何设置 Mono 的路径以便主管知道它?

c# - MVC4/我想要的是局部 View 吗?

c# - View 中具有自定义模型属性的 MVC3 默认成员属性(使用 ModelView?)

c# - 使用 Razor Helper 有条件地包装内容

javascript - 如何告诉 Razor 不要 html 转义

ruby-on-rails - 在 Rails View 中显示整个实例变量

c# - Nancy,TinyIoC - 卡在盒子里

c# - NancyFx 测试返回无效的 Json

javascript - 从 View 中的 Javascript 访问 MVC3 模型属性