Ed DeGagne
Ed DeGagne

Reputation: 3269

Full Site link on Mobile Site

Reaching out to the community here for a best practice/best implementation question.

I am using MVC3 in a major project, the MVC3 site will handle both our full site as well as our mobile site in a single solution. I have created a custom view engine to handle mapping mobile requests to the appropriate mobile views.

A requirement that popped up recently is to have a "Full Site" link on the mobile portion of the site to allow a mobile user to view the full site (actually to be able to switch back and forth).

Anyone have any insight on a possible quick solution or done something similiar?

I have a separate layout file (master page) for my mobile views that the "Full Site" link appears on.

Thanks in advance for any possible answers.

Upvotes: 2

Views: 1466

Answers (3)

Sergi Papaseit
Sergi Papaseit

Reputation: 16174

Maybe I'm misunderstanding your question, but if you're asking how to link the two "versions" of the site, wouldn't it be as "simple" as having two Areas?

Each area will define its own routes, with the mobile area starting its routes with, for instance:

context.MapRoute(
        "Mobile_Default",
        "mobile/{controller}/{action}/{id}",
        new { action = "Index", id = UrlParameter.Optional }
    );

so it's quite easy to link from one area to the other:

@Html.ActionLink("non-mobile site", "index", "home", new { area = "" }, null)

and the other way round:

@Html.ActionLink("Mobile site", "index", "home", new { area = "mobile" }, null) 

Upvotes: 0

Tengiz
Tengiz

Reputation: 8389

This should be something like a parameter for sure, view engine needs to know about the user preference. So it chooses the default view as it does now, but checks some parameter if the user preference does not match the default option.

Cookie, URL param...

Upvotes: 1

Ryan Tofteland
Ryan Tofteland

Reputation: 913

There are a few different ways you could go. A couple ideas:

  1. Store a cookie when the user clicks "View Classic" or "View Mobile" that your custom view engine can check before directing to the appropriate view.
  2. Take a look at the 51Degrees.mobi .NET library that handles mobile detection and redirection. There is a feature that can be used to track a user's preference (see firstRequestOnly config option). Steve Sanderson has a good blog overview on implementing this library in MVC3: http://blog.stevensanderson.com/2010/12/17/using-51degreesmobi-foundation-for-accurate-mobile-browser-detection-on-aspnet-mvc-3/

Upvotes: 3

Related Questions