Reputation: 4415
I have a small MVC web project where I want to be able to achieve the following:
To help achieve this I have created a layout object with the following properties:
public class PageLayout {
public string Reference { get; set; }
public string Domain { get; set; }
public string LayoutPath { get; set; }
public string CssPath { get; set; }
public string JavaScriptPath { get; set; }
}
My idea being that at the start of the session, the URL will be checked for a layout parameter. For example:
http://www.{Domain}.com/tech
In this instance, the Pagelayout object with the Reference "tech" would be retrieved. If no parameter was found then the Page Layout object with its Domain property matching the active domain would be retrieved.
I have several questions regarding the right way to implement this:
How do I make the Pagelayout data available to each page. I thought about creating a custom Controller and then adding it to the ViewBag (from the Session), so the master view could implement something like the following:
@{ Layout = ViewBag.Pagelayout.LayoutPath; } ...
Are the better/cleaner/more appropriate mechanisms available to achieve what I need?
Upvotes: 0
Views: 572
Reputation: 2573
Yes there are cleaner ways to do, like using some third party tool and to hook it your application.
You can take a look at this site, this is the latest that have been introduced recently http://razorc.net/
Also take a look at http://www.codeproject.com/Articles/32847/ASP-NET-MVC-Dynamic-Themes http://codeofrob.com/entries/dynamically-switching-between-master-pages-in-asp.net-mvc.html
Upvotes: 1