Passing Data to a Layout Page
.net, asp.net, asp.net-mvc-3, razor
Solution
OK since you want this to be set once you can make use of a partial view. However depending on your needs you will need to have several partial views (may be not ideal if sections are going to be scattered across the _layout page)
your partial view will look like
@model KarateAqua.schoolModel
<div class="bottom_logo">
<a href="/"><span class="inv">@Model.schoolName</span>
</div>
Controller
public class SchoolController : Controller
{
public ActionResult Index()
{
//get schoolModel
return PartialView(schoolModel);
}
}
in your _layout.cshtml place this line where you want to have the partial view to be inserted
@Html.Action("Index","School")
Problem
I have a `layout` page that has variables that need to be filled. Example: ``` @ModelType KarateAqua.schoolModel <html> <body> @RenderBody() <div id="footer"> <div class="content"> <div class="bottom_logo"> <a href="/"><span class="inv">@Model.schoolName</span></a> </div> </div> </div> </body> </html> ``` I don't want to populate this in every `ActionResult`. Is there a way to pass data to a `layout` page once and do it for all instances?