Is it possible for a Master page to access Controller properties?


Is it possible for a Master page to access Controller properties?



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?




How to enable/Disable textbox. and also make text box blank on change of value in the drop down list

1:



How to pass data from a jquery dialog back to a controller's action to update the dialog
It turns out the following worked, which I figured out from here.
How do you set or remove generated label styles from the jQuery Validation plugin?
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);         ViewData["WrapperTop"] = wm.WrapperPartOne;         ViewData["WrapperBottom"] = wm.WrapperPartTwo;          base.Initialize(rc);     } } 
And then in the Master page:.
ASP.NET MVC Trouble getting data and related data to the view. (View Model Pattern?)
<%= (string)ViewData["WrapperTop"] %>      <div>         <asp:ContentPlaceHolder ID="MainContent" runat="server">          </asp:ContentPlaceHolder>     </div>      <%= (string)ViewData["WrapperBottom"] %> 


Combining ASP.NET MVC and Reverse Proxy with URL Rewrite v2


51 out of 100 based on 26 user ratings 551 reviews