Webmatrix Layout — Inserting into head?

血红的双手。 提交于 2019-12-12 17:13:09

问题


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).

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).

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.

Thanks in advance for any assistance.


回答1:


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

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

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



来源:https://stackoverflow.com/questions/5569182/webmatrix-layout-inserting-into-head

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!