How to Make Desktop and Mobile site with ASP.NET MVC 4

Leave a Comment
In this tutorial, you have to learn how to create mobile and desktop version of website in MVC 4 ASP.Net.

In this article, we have to refer previous article so go to below link and get the source code.

Now we have just add the below code into the global.asax file -
 DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
            {
                ContextCondition = (ctx => ctx.Request.UserAgent != null
                                            && (ctx.Request.UserAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) >= 0
                                                || ctx.Request.UserAgent.IndexOf("Mobile", StringComparison.OrdinalIgnoreCase) >= 0
                                                || ctx.Request.UserAgent.IndexOf("Opera Mobi", StringComparison.OrdinalIgnoreCase) >= 0
                                                || ctx.Request.UserAgent.IndexOf("Opera Mini", StringComparison.OrdinalIgnoreCase) >= 0))
            });

Than you have to create two views and also you have to create two views for master page _Layout.cshtml and _Layout.Mobile.cshtml and add add two different content (e.g. css, js, images) as shown below screen -
_Layout.cshtml - For Desktop version.
_Layout.Mobile.cshtml - For Mobile version.

Now, test your application.

0 comments:

Post a Comment