Display Mode in ASP.NET MVC4

It was mentioned here that when the browser is mobile, ASP.NET MVC4 will request _Layout.Mobile.cshtml. This is not happening.

Any configuration needed to enable this feature?

+4
source share
6 answers

According to the ASP.NET team ( http://www.asp.net/whitepapers/mvc4-release-notes ):

If your Views \ Shared folder contains both _Layout.cshtml and _Layout.mobile.cshtml, by default the application will use _Layout.mobile.cshtml during requests from mobile browsers and _Layout.cshtml during other requests.

If you have these files, the problem may be that the mobile engine was not detected correctly, can you tell us if you upgraded the MVC 3 project to MVC 4 or created a new MVC 4 project? If firstly, I recommend that you try creating a new MVC 4 project and see if the problem persists, if your installation of MVC 4 is probably a little damaged ...

EDIT: You need to copy Views \ Shared_Layout.cshtml to Views \ Shared_Layout.Mobile.cshtml. Since it does not seem to be added automatically.

+4
source

I ran into the same problem, found a solution here http://51degrees.mobi/Support/Blogs/tabid/212/EntryId/26/51Degrees-mobi-and-MVC4.aspx

Greetings

+2
source

First ... make sure you have an MVC4 project - either cleaned from the template, or the Microsoft update instructions are correctly followed.

As in other versions of MVC, the project structure works by convention, and usually the views should be in certain folders - for example, the Views for your FoodController are expected to be in Views -> Food , and the templates are expected to be in Views -> Shared .

Assuming _Layout.Mobile.cshtml is located in the Shared Views folder, it may be case sensitive - _Layout.Mobile.cshtml , although I doubt it.

Do you use Fiddler to verify the sent request (headers and UA) and the Response response?

+1
source

I have the same problem, in my case I upgraded from MVC3 to MVC4, but I think Im missing something. Interestingly, it works for the iPhone browser, but not for androids (at least some of them). It works great in a clean mvc4 project. So I'm not sure what I lost, I will go back to mvc3> 4 update instructions again to see what I missed. If I donโ€™t see anything, I will try to implement the implementation using 51devices or clear the MVC4 project.

UPDATE: The following update instructions again, I do not see anything that I missed. So I ended up implementing the 51devices method according to these instructions: http://51degrees.mobi/Support/Blogs/tabid/212/EntryId/26/51Degrees-mobi-and-MVC4.aspx Android devices, it seems now good display mobile display. The only update is to use:

 `DisplayModeProvider.Instance.Modes.Insert` 

instead

  `DisplayModes.Modes.Insert` 
+1
source

Make sure your mobile browser sends the correct user agent strings, especially if you are using a mobile browser emulator. I am fortunate that the new chrome user agent is being redefined in the console settings and some plugins for Firefox.

0
source

If you have areas in your MVC application, you will need to modify _ViewStart.cshtml inside each area.

0
source

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


All Articles