Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mobile Specific Views / Device Detection

In the .NET Core docs there is a page titled "Building Mobile Specific Views" but is under construction: https://docs.asp.net/en/latest/mvc/views/mobile.html.

Does anyone have some insight on building mobile views or successfully doing device detection?

like image 584
Tyson Nero Avatar asked Jul 12 '16 14:07

Tyson Nero


2 Answers

Serving specific views based on the browser's user-agent is an outdated concept as it do not sufficiently says much about the capabilities of the device. For example, iPhone and iPad come in different screen sizes and even mobile browsers allow to change the user-agent.

The new concept is called Responsive Design where one creates a single page that fits and show/hides certain element based on the available screen width. One popular responsive deisgn CSS Framework is Bootstrap, originally developed by Twitter and later open-sourced.

Here is an example of responsive design. When you go to the site and change the width of your browser, the design updates as well from 3 to 2 to 1 column design with browser or mobile like navigation (with the Hamburger menu).

like image 194
Tseng Avatar answered Oct 14 '22 01:10

Tseng


This feature actually was not implemented by microsoft. There is couple open discussions for this question:

  • https://github.com/aspnet/Mvc/issues/4877

  • https://github.com/aspnet/Razor/issues/751

As a generic answer from them - use responsive web design and css media queries (which from my point of view is not perfect answer for team that claims himself for building general web framework). There is a implementation for this feature exist as pull request - https://github.com/aspnet/Mvc/pull/4878.

Since this pull request seems to be forgotten, i extract this code into separate project which is available on https://github.com/laskoviymishka/MvcDeviceDetector.

You may use this implementation (which is easy to add to exist MVC project) or implement this itself. This is pretty easy - you need just implement and reqister own IViewLocationExpander for that.

like image 1
Andrei Tserakhau Avatar answered Oct 14 '22 01:10

Andrei Tserakhau