13

I have rendering a section in the bottom master layout. This is typically section to render javascript at the bottom of the page when it renders. Defining that section in View and _partial views. When page renders, it renders section from page view but not from the _partial view.

How it is possible to render a section defined in _partial view to main layout?

Paul Tyng
  • 7,924
  • 1
  • 33
  • 57
Nps
  • 1,638
  • 4
  • 20
  • 40
  • @Html.Partial("NameOfPartial", ModelForPartial) if i understood you. It's hard to understand what do you want. – Alleo Sep 04 '11 at 13:06
  • 7
    This is not supported. Sorry. One possible solution is to use custom helpers as shown in this duplicate question: http://stackoverflow.com/questions/5433531/using-sections-in-editor-display-templates/5433722#5433722. – Darin Dimitrov Sep 04 '11 at 13:09
  • Why can't I access System.Web.Mvc name space in App_Code folder. I am creating extension method in App_Code class. I am not able to see this name space in the intellisence while adding to the extension class. Neither it is recognize HtmlHelper as know type. – Nps Sep 04 '11 at 14:42
  • However namespace System.Web.Mvc is not being coming up in Intellicese but application is compiling so extensions is seems working for me. Thanks – Nps Sep 04 '11 at 15:20
  • Why do you want that? Partial Views should provide some flexibility and should be perfectly reusable. Aren't you creating unwanted dependency (with a Layout view) with that, don't you? – S P Apr 24 '12 at 09:29

1 Answers1

3

You can use Html.RenderAction/Html.Action or use helpers like demonstrated here: https://stackoverflow.com/a/5433722/290343

Community
  • 1
  • 1
Ofer Zelig
  • 17,068
  • 9
  • 59
  • 93