0

I have created an adaptive website in MVC4. I know how to switch between desktop and mobile view for entire website using viewswitcher. My problem is I want to switch a single page to desktop view when a person visits that page from mobile device.

For Eg : There is an ActionResult Test, So when a person visits this page (Test) from Desktop then by default desktop view is displayed but when a person visits the same page from mobile again desktop view should be displayed instead of mobile. As my website is adaptive so there is a _Layout.Mobile.cshmtml page which is rendered automatically when a person is coming from mobile. To avoid this I had created test.Mobile.cshtml page in which I have set Layout = null; and copy pasted all the _Layout.cshtml html but as there are media queries for Mobile device all my Desktop css is getting overridden which doesn't serve the purpose.

So my question is how to switch a single page between desktop and mobile instead of entire site. All the other pages should function as it is (adaptive).

2 Answers2

0

Assuming the view in question is a "full" page (meaning it has no layout page and includes a well-formatted, complete HTML page), you would just need to omit the viewport meta tag from the head of that view. If you're not familiar with the viewport, Google has a decent post about it here: https://developers.google.com/web/fundamentals/layouts/rwd-fundamentals/set-the-viewport

If you need the "desktop mode" to be switchable, then simply add a conditional around the viewport element:

@if(ViewBag.EnableViewportScaling)
{
    <meta name="viewport" content="width=device-width, initial-scale=1" />
}

where I assume you can add a Boolean property to ViewBag at some point prior to rendering the view's markup.

Tieson T.
  • 20,774
  • 6
  • 77
  • 92
0

As I understand, this code must be located in `_ViewStart.cshtml':

@{
  if (isDesktopClient)
      Layout = "~/Views/Shared/_Layout.cshtml";
  else
      Layout = "~/Views/Shared/_Layout.mobile.cshtml";
}

So you need use the condition if (isDesktopClient || Request.Path == "~/Test").

Mark Shevchenko
  • 7,937
  • 1
  • 25
  • 29