I need to load a HTML wrapper dynamically depending on data that gets populated in the PageController
, which is a base class that all other controllers implement.
This is the PageController:
public class PageController : Controller
{
protected PageConfiguration PageConfiguration;
public string WrapperTop { get; set; }
public string WrapperBottom { get; set;}
protected override void Initialize(RequestContext rc)
{
// the PageConfiguration is determined by the
// Controller that is being called
var pageName = rc.RouteData.Values.Values.FirstOrDefault();
this.PageConfiguration = GetPageConfiguration(pageName.ToString());
WrapperManager wm = GetWrapperManager(this.PageConfiguration.Id);
this.WrapperTop = wm.WrapperPartOne;
this.WrapperBottom = wm.WrapperPartTwo;
base.Initialize(rc);
}
}
I'm currently implementing my Master page as follows:
<% Html.RenderAction( "GetWrapperTop", "FundFactsheet"); %>
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<% Html.RenderAction("GetWrapperBottom", "FundFactsheet"); %>
But this means that I have to have GetWrapperTop()
& GetWrapperBottom()
defined in all Controllers that need a wrapper, and I also have to have a Master page for every type of Wrapper that I want. For instance, the Master page for SearchResultsController would have:
<% Html.RenderAction("GetWrapperBottom", "SearchResults"); %>
Ideally it'd just be
<%= this.WrapperTop %>
<div>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
<%= this.WrapperBottom %>
How can the Master page access the WrapperTop
and WrapperBottom
values in PageController
?