4 ms·
The automatic support for routing to .mobile views is really nice, for one thing. The small improvements to Razor (e.g. automatic ~/ parsing and conditional sh
by Encosia 14y ago
The automatic support for routing to .mobile views is really nice, for one thing.
The small improvements to Razor (e.g. automatic ~/ parsing and conditional shortcuts) are also nice time/trouble savers.
- vyrotek 14y agoI've been following MVC for a long time and I somehow completely missed the .mobile.cshtml feature! I can actually make use of this now. Thanks :)
- jongalloway2 14y agoThe .mobile.cshtml is included out of the box, but you can also define other specific display modes with a lambda expression: DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone") { ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0) }); After calling that, you can create a view (index.iphone.cshtml) and it'll be automatically picked up when the condition's matched. This example uses the user agent, but you can use any logic you'd like - cookie / database call / time of day / whatever.
- vyrotek 14y agoVery nice! What's the best way to develop and debug mobile sites locally? Is there a quick way to force either my browser or VS to go into 'mobile' mode? Edit - Found the answer :) http://www.howtogeek.com/113439/how-to-change-your-browsers-user-agent-without-installing-any-extensions/ http://www.howtogeek.com/113439/how-to-change-your-browsers-...