开发者

Webmatrix Layout -- Inserting into head?

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 X开发者_运维问答ML (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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜