【问题标题】:Nancy - Super Simple View Engine: How do I override a MasterPage's title in the view?Nancy - 超级简单的视图引擎:如何在视图中覆盖 MasterPage 的标题?
【发布时间】:2012-03-29 17:58:36
【问题描述】:

我想从相应的视图中设置每个渲染页面的title。我还想在我的母版页中设置一个默认标题。这是我正在使用的超级简单的设置。

母版页

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>NancyFX is Splendid</title>
</head>
<body>
    @Section['Content']
</body>
</html>

查看

@Master['_Master']
@Section['Content']
    <h1>Home</h1>
    <p>Hello @Model.UserName</p>
@EndSection

我已经尝试了一些更明显的猜测,但到目前为止没有任何乐趣。你能帮忙吗?

更笼统地说 - Nancy 的 SSVE 是否有任何明确的帮助?我已经阅读了网站和 GitHub 上所有可用的文档,但它们很少。只需列出所有 SSVE '@[]' 关键字,就可以节省很多时间。

谢谢

【问题讨论】:

    标签: nancy


    【解决方案1】:

    您可以只从模型中渲染它,就像其他任何东西一样:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Hello @Model.Name!</title>
    </head>
    <body>
    <h1>Super Simple View Engine</h1>
    <p>This text is in the master page, it has access to the model:</p>
    <p>Hello @Model.Name!<p>
    @Section['Content']
    </body>
    </html>
    

    至于文档,大部分标签都记录在这里:https://github.com/grumpydev/SuperSimpleViewEngine 虽然现在有点过时了。它最初是为内部使用而设计的,但显然,如果您愿意,欢迎您使用它。如果您遇到困难,最好查看测试,那里有所有标签的示例。

    【讨论】:

    • 母版页可以访问视图模型是吗?现在这很聪明,并且几乎可以解释为什么如果不是这样,我无法为您需要的所有无数关键字找到帮助:-) 谢谢。我现在开始跑步了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多