开发者

asp.net MVC razorview rendersection

I wonder how to input @section in the partial view in Razor view. Is that possible or I must put it in a vie开发者_StackOverflow社区w only?

Thanks.


Why not try just creating a partial view that has all the javascript and css you want and just rendering that partial view in the layout? I don't think you need sections to get that done. The point to sections is to tell full views that they can have specific sections just for them and that the partial views won't force them to look like anything.

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    @Html.Partial("_HeaderLinksAndScripts")
</head>
<body>
    <div class="page">
        <div id="header">
            <div id="title">
                <h1>My MVC Application</h1>
            </div>
            <div id="logindisplay">
                @Html.Partial("_LogOnPartial")
            </div>
            <div id="menucontainer">
                @Html.Partial("_MenuPartial")
            </div>
        </div>
        <div id="main">
            @RenderBody()
        </div>
        <div id="footer">
            this is a footer
        </div>
    </div>
    @Html.Partial("_FooterScripts")
</body>
</html>

Just put the site-wide css and javascripts in the appropriate partial views.


Put your scripts in that partial view not in a section (since you cant do @section in a partial) OR simply put them in your main layout and control their rendering conditionally.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜