I'm working on updating a project where many different views share the same layout, with only minor differences in content between them.
The basic layout looks like this:
@Html.Partial("_HeadingBar")
<div class="panel grid_4">
<div class="panel-header">
<span>@ViewBag.SmallHeader</span>
</div>
<div class="panel-body">
<div class="panel-content">
@* Welcome.cshtml:
<p>Please use the navigation bar on the side of the site to utilize the features of the site.</p> *@
@* Login.cshtml:
@using (Html.BeginForm())
{
if (!ViewData.ModelState.IsValid) ...
<div class="form-row-inline">
@Html.LabelFor(m => m.UserName)
@Html.TextBoxFor(m => m.UserName)
@Html.ValidationMessageFor(m => m.UserName)
</div>
...
<button type="submit" class="btn btn-success"><i class="icon-lock"></i> Sign In</button>
} *@
@* ChangePassword.cshtml:
@using(Html.BeginForm())
{
...
@Html.LabelFor(m => m.NewPassword)
@Html.PasswordFor(m => m.NewPassword)
@Html.ValidationMessageFor(m => m.NewPassword)
...
} *@
</div>
</div>
</div>
My thought was to strip each view down to the unique content and make it a partial view, and make the shared part into a regular view.
But I'm not sure that's the correct way to do this. Adding Html.RenderPartial
would result in a second call to the server, and would require additional Actions to be added to the Controller.
It seems like I'm looking for a layout, but the site already uses a layout.
What's the correct/best-practice way to handle this?