tags:

views:

1585

answers:

4

I have the requirement to support different Master pages on my application (ASP.NET MVC). What is the recommended way to: 1- Pass the master page name to the view from. 2- Store the master page (in session, or something) so it sticks during a user's visit.

Thank you.

A: 

you could throw the master page name into the session, but sessions are unreliable. i'd recommend throwing it in a db instead.

once you're in the page, you can change/set the master page by accessing page.masterpagefile. it's a string; just pass the .master name in.

A: 

Why not keep the Master Page on the user profile? Then just change it on the PreLoad event.

http://www.odetocode.com/articles/440.aspx

Bruno Figueiredo http://www.brunofigueiredo.com

Bruno Shine
I'm using ASP.NET MVC. Shouldn't the controller decide what page to use?
pgb
yep. Probably you should use a base controller.
Bruno Shine
A: 

See my answer for another similar question here

Matthew
+6  A: 

Use a custom base controller and inherit from it instead:

Public Class CustomBaseController
    Inherits System.Web.Mvc.Controller

    Protected Overrides Function View(ByVal viewName As String, ByVal masterName As String, ByVal model As Object) As System.Web.Mvc.ViewResult

       Return MyBase.View(viewName, Session("MasterPage"), model)

    End Function

End Class

I set my Session variable in the global.asax Session_Start:

Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)

//programming to figure out your session
Session("MasterPage")="MyMasterPage"

End Sub
Slee