Mobile device views / device discovery

There is a page in the .NET Core docs called "Creating Mobile Specific Views", but is under development: https://docs.asp.net/en/latest/mvc/views/mobile.html .

Does anyone have any idea about creating mobile views or successfully discovering devices?

+5
source share
2 answers

Serving specific views based on the browser user agent is an outdated concept because it doesn't talk enough about device capabilities. For example, iPhone and iPad have different screen sizes, and even mobile browsers allow you to change the user agent.

The new concept is called Responsive Design, where one page is created that fits and displays / hides a specific element based on the available screen width. One popular deisgn CSS system is Bootstrap , originally developed by Twitter and later open.

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

+1
source

This feature was not actually implemented by Microsoft. There are a couple of open discussions on this issue:

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

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

As a general answer from them - use responsive web design and css-media queries (which, in my opinion, is not an ideal answer for a team that claims to create a common web framework). There is an implementation for this function in the form of a tensile request - https://github.com/aspnet/Mvc/pull/4878

Since this pull request seems to be forgotten, I am extracting this code into a separate project, which is available at https://github.com/laskoviymishka/MvcDeviceDetector

You can use this implementation (which is easy to add to an existing MVC file) or implement it yourself. It's quite simple - you just need to implement and rewrite your own IViewLocationExpander for this.

+1
source

All Articles