Reputation: 1713
I am working on a website with desktop and mobile views, using MVC5. The project has separated layouts for each version:
_Layout.cshtml
_Layout.Mobile.cshtml
In _ViewStart.cshtml, the following line should make mobile devices display the .Mobile.cshtml version of the views if they exist, and the desktop version otherwise:
DisplayModeProvider.Instance.RequireConsistentDisplayMode = true;
Problem:
The problem I have is that some of the views without a .Mobile version are displayed using the _Layout.Mobile, while some other views behave as expected.
What I have tried:
I have forced a browser override in the problematic views .cshtml file:
Request.RequestContext.HttpContext.SetOverriddenBrowser(BrowserOverride.Desktop);
However, this solution is not acceptable because the override persists and when the user continues navigating the site, all pages are now displayed in desktop mode even if they should not.
Another unacceptable solution is to manually clear the override when exiting this screen, because users may have selected to view the desktop version, and we would be reverting their action.
The actual question(s):
How can I force a view into desktop mode without making this change persist when the user continues navigating? Is there anything else regarding mobile views that I am missing?
Upvotes: 3
Views: 1023
Reputation: 1713
I have been able to solve this issue. What I have done is a walkaround, not a proper solution, but may be helpful if someone else faces this situation.
I have created a different Layout file, let's say I have named it _Layout.DesktopForMobile.cshtml
. It is basically the same as _Layout.cshtml (except that I took the opportunity to have minor differences in the new file, specific for those pages that will have default layout in mobile devices). I manually force the troublesome views to use my new layout, and as this one does not have .Mobile version, they are displayed ok.
Upvotes: 1