ASP.NET MVC BaseController for dynamically setting a MasterPage file

I built a base controller that all my controllers inherit from, and I have it configured so that it checks the browser type and immediately returns the corresponding MasterPageFile.

I am wondering if this is an effective way to do this, or if I have to optimize it differently.

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

Also, if anyone is interested, I use the information found here to improve my checks Request.Browser.IsMobileDevice.

The file .browserI use can be found here .

+3
source share
2 answers

IMHO : (, , HTTP- ) , .

+1

ViewPage, .. BaseViewPage, ?

: :

ASP.NET MVC RC 1.0

0

Source: https://habr.com/ru/post/1748712/


All Articles