How do you put a strongly typed object in ASP.NET MVC into the master page?
Do you have a ViewModelBase
class that contains master page information and inherit from it for every view model, or is there a better approach?
To set the master page programmatically, then, we can either create an event handler for the PreInit event or override the OnPreInit method. Let's look at both approaches. From here we can set the MasterPageFile property. Update the code so that it assigns the value "~/Site.
The @Page directive page binds the content page to a specific master page. It defines a title for the page to be merged with the master page. User can create content by adding content controls and mapping them to the contentplaceholder controls on the master page.
What are master pages? Master pages are used to create consistency from page to page in a document. Master pages typicially contain page headers, footers, margin and column guides, and other elements that occur on multiple pages in your document.
A content page is an ASP.NET Web page that is associated with a master page. The master page establishes a layout and includes one or more ContentPlaceHolder controls for replaceable text and controls.
Alex,
I think what you are asking is, "Where is my master page controller?"
Have a look at the following link. It explains how to create an "Application Controller," an abstract class that can be inherited by your other controllers, so that you only have to write the code once that pushes your needed master page data into the view.
Passing Data to View Master Pages:
http://www.asp.net/learn/MVC/tutorial-13-cs.aspx
Also, have a look at the following link, which explains how to implement Partial Views and Subcontrollers in ASP.NET MVC:
Partial Requests in ASP.NET MVC
http://blog.codeville.net/2008/10/14/partial-requests-in-aspnet-mvc/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With