Reputation: 473
I have a Partial View which shows on multiple pages. The problem I am facing after implementing it is, The position of the partial view is beiong shuffled on different views. Each of the views have their own css layout. So, should I change the css layout of all the views or is there any workaround for it...
Upvotes: 0
Views: 531
Reputation: 2126
Typically you would render shared partials like here:
One way to do it is to have two Layouts for your pages. Have the default _Layout.cshtml and _LayoutWithSomething.cshtml and then in your Views determine which one to use
@{
Layout = "~/Views/Shared/_LayoutWithSomething.cshtml";
}
Another way to do this is to put RenderSection block in your _Layout.cshtml
<div class="main-content">
@RenderSection("submenu", false)
@RenderBody()
</div>
And then use @section in your views, note that this doesn't work inside partial views.
@section submenu
{
@Html.Partial("_MyPartial")
}
If your css completely changes the layout I'd split the css into two: layout aspect of styling and then the others like colors etc.
Upvotes: 2