How do you switch _layout.cshtml based on Screen vs Handheld? (.NET MVC3)

I am developing a small website that I want to be able to view both on a computer and on a mobile device. I understand that I can easily change my CSS code for most mobile devices using the following:

<link rel="stylesheet" type="text/css" media="handheld" href="foo_mobile.css"> <link rel="stylesheet" type="text/css" media="screen" href="foo_screen.css"> 

However, I really want to replace _layout.cshtml based on the type of browser (screen and handheld - plus iPhone).

I have seen many sites that redirect mobile devices to a subdomain, such as m.xyzCorp.com , but would like to avoid this if possible.

Is there any sample code or tutorials? my google-foo is weak today.

TIA

+4
source share
1 answer

There is something like this in _ViewStart.cshtml

 @{ if (!Request.Browser.IsMobileDevice) { Layout = "~/Views/Shared/_Layout.cshtml"; } else { Layout = "~/Views/Shared/_MobileSiteLayout.cshtml"; } } 
+7
source

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


All Articles