Webmatrix布局-插入头部吗? [英] Webmatrix Layout -- Inserting into head?

查看:46
本文介绍了Webmatrix布局-插入头部吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Asp.Net和Razor视图引擎(与使用WebMatrix相同)创建了一个网站.到目前为止,我一直在使用SQL直接查询数据库,但是现在我有一个页面需要查询返回XML的WCF服务(获取返回JSON或ODATA的查询可能是一个单独的问题).

I've created a web site using Asp.Net and the Razor view engine (which is the same as using WebMatrix). Up to now, I've been using SQL to query databases directly, but now I have a page which needs to query a WCF service that returns XML (getting that to return JSON or ODATA maybe is for a separate question).

在这样做时,我一直在寻找最好的方法,似乎 jQuery 可能是答案(除非您有其他想法).

On doing this, I was looking at the best way to do this, and it seems that jQuery may be the answer (unless you have other thoughts).

问题是我正在使用Layout =〜/SiteLayout.cshtml"使用SiteLayout,但无法弄清楚如何将特定于此页面的额外信息覆盖或插入到SiteLayout中的head标签中,例如我需要添加的脚本?

The problem is I'm using SiteLayout using the Layout="~/SiteLayout.cshtml" and I can't work out how to override or insert extra information specific to this page into the head tag that is in the SiteLayout, such as the script I need to add?

我很确定我正在考虑这个错误,因此,如果有人能将我的方向指向正确的方向,那将是很好的.

I'm pretty sure I'm thinking about this wrong, so if anyone has the answer to point me in the right direction, that would be great.

在此先感谢您的帮助.

推荐答案

您可以在子页面中定义 Head 部分:

You can to define a Head section in the child pages:

@section Head {
    <script> ... </script>
}

然后您可以在布局页面的< head> 中调用 RenderSection("H​​ead")来呈现此部分.
您可能要传递,必填:false .

You can then call RenderSection("Head") in the <head> in the layout page to render this section.
You may want to pass , required: false.

有关更多信息,请参见

For more information, see ScottGu's blog post

这篇关于Webmatrix布局-插入头部吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆