asp.net mvc - Dynamically Managing MVC Layouts -
i have small mvc web project want able achieve following:
- select base page layout , css/javascript based upon active domain
- optionally allow base/default setting overridden @ start of session.
to achieve have created layout object 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 @ start of session, url checked layout parameter. example:
http://www.{domain}.com/tech
in instance, pagelayout object reference "tech" retrieved. if no parameter found page layout object domain property matching active domain retrieved.
i have several questions regarding right way implement this:
- where best place implement logic in mvc? session_start method in global.asax seems potential candidate
- i want persist retrieved pagelayout object across whole session. going add session state via kind of management class.
how make pagelayout data available each page. thought creating custom controller , adding viewbag (from session), master view implement following:
@{ layout = viewbag.pagelayout.layoutpath; } ...
are better/cleaner/more appropriate mechanisms available achieve need?
yes there cleaner ways do, using third party tool , hook application.
you can take @ site, latest have been introduced http://razorc.net/
also take @ 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
Comments
Post a Comment