Question

I have an application that needs to support both desktop and tablet browsing. Both versions will be significantly different, using different Layouts in /Views/Shared/

In the Controller I am currently reading the user agent string and returning different Partial Views, which are parsed within the one Layout. I want to have two different Layouts, one which gets rendered for tablets and one for desktop. Currently I have:

/Views/Shared/_HomeLayout.cshtml
/Views/Shared/_HomeLayoutTablet.cshtml

How do I read the user agent string and have the server render the correct View before my own Controllers get called?

Était-ce utile?

La solution

You can still use mobile views and the contextcondition to return a different view, even for partials.

http://www.asp.net/mvc/tutorials/mvc-4/aspnet-mvc-4-mobile-features

From the examples in this post, if you wanted a view to be considered only for a mobile, you create 2 versions, one with the .mobile.cshtml extension.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top