Asp.net MVC 5 Customized Mobile based View For Iphone,Android,Windows Phone

Asp.net MVC 5 has great feture called Mobile based separate view , suppose your View for all application is index.cshtml, you need to separate your view for iPhone and android.

Now , install Razor view engine 3.0 and make a new view for iPhone called index.iPhone.cshtml and index.Android.cshtml.

And separate view in shared and layout also.

Now add this below lines to in Global.asax to identifying for iPhone And Android Request and redirecting to
Specified view.

   DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("iPhone")
            {
                ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
                    ("iPhone", StringComparison.OrdinalIgnoreCase) >= 0)
            });

            DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Android")
            {
                ContextCondition = (context => context.GetOverriddenUserAgent().IndexOf
                    ("Android", StringComparison.OrdinalIgnoreCase) >= 0)
            });

You Might Also Like

Leave a Reply