Just add ViewBag.IsHome = true; to the home controller, index the action method controller.
Then add this to the _layout.chtml :
@if ((bool?)ViewBag.IsHome){ Html.RenderPartial( "_HomeContentPartial .cshtml" ); }
Another option:
As you can specify as many rendering areas as you want in the layout, just add placeholders for the extra parts and use @RenderSection with the required flag set to false so that it doesn't mind if it's missing.
eg. in your _layout.cshtml
@RenderSection ("extraheader", false)
then in a view that has optional parts to insert at this position:
@section extraHeader{ <ul> <li>Some new option 1</li> <li>Some new option 2</li> </ul> }
Which method you will use will depend on how you want to reuse the components. You can happily display a partial view inside @section to allow reuse in many views:
eg.
@section extraHeader{ @Html.Partial("somepartialview") }
or even using another controller action (encapsulation is better, so I prefer):
eg.
@section extraHeader{ @Html.Action("someAction", "someController", new {id = someValue}) }
source share