3

I call in my page layout to the menu page with "Html.Action" and I have a section for "javascript" for include javascript code:

Shared/layout.chtml

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">

    <script src="@Url.Content("~/Scripts/jquery-1.6.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/Modules/Site.js")" type="text/javascript"></script>

    @RenderSection("javascript", required: false)

</head>

<body>
    <div id="menucontainer">
        @Html.Action("Menu", "Controls")
    </div>

    <div id="main">
    @RenderBody()
    </div>
</body>
</html>

but the menu does not come to include in section "javascript":

Controls/Menu.chtml

@section javascript
{
    <script src="@Url.Content("~/Scripts/Modules/Site.Controls.Menu.js")" type="text/javascript"></script>
}

<ul class="sf-menu">
  <li class="current">
    <a href="#">Menu</a>
    <ul>
      <li>@Html.ActionLink("Home", "Index", "Home")</li>
      <li>@Html.ActionLink("WebGrid Sample", "WebGridSample", "Grids")</li>
    </ul>
  </li>

</ul>

How I can do to include the javascript call in the section "javascript"?

thanks

Prasanth
  • 3,029
  • 31
  • 44
andres descalzo
  • 14,887
  • 13
  • 64
  • 115
  • Should that be `menu.cshtml` ? – Chris S Oct 20 '11 at 14:09
  • I am lost behind belief as to your logic. Why do you have a javascript section that is a script reference. Why not skip the "section" part and just have the javascript reference straight in your menu.cshtml file? – musefan Oct 20 '11 at 14:13
  • @musefan so that when rendering the page, javascript calls are in the header, instead of appearing on any side – andres descalzo Oct 20 '11 at 14:17
  • I can see it will place in the header, but at what benefit? – musefan Oct 20 '11 at 14:19
  • 2
    look at this : http://stackoverflow.com/questions/7556400/injecting-content-into-specific-sections-from-a-partial-view-asp-net-mvc-3-with – tugberk Oct 20 '11 at 14:20
  • @tugberk yes, it gives me a solution, but I have to include the call to the calling script after the pages with "Html.Action" – andres descalzo Oct 20 '11 at 15:03

1 Answers1

3

Sections are not supported when calling an MVC view via @Html.Action or @Html.Partial. Sections are only supported between the view and its immediate layout.

marcind
  • 52,944
  • 13
  • 125
  • 111