ASP.NET MVC BaseController to dynamically set MasterPage file
Posted
by rockinthesixstring
on Stack Overflow
See other posts from Stack Overflow
or by rockinthesixstring
Published on 2010-06-06T08:09:30Z
Indexed on
2010/06/06
8:12 UTC
Read the original article
Hit count: 354
asp.net-mvc
|masterpage
I've built a Base Controller that all of my Controllers inherit from, and I've got it setup so that it checks the browser type and returns the appropriate MasterPageFile on the fly.
I'm wondering if this is an efficient way to do this or if I should optimize it another way.
Public Class BaseController : 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
If Request.Browser.IsMobileDevice Then
Return MyBase.View(viewName, "Mobile", model)
Else
Return MyBase.View(viewName, "Site", model)
End If
End Function
End Class
© Stack Overflow or respective owner