1
votes

We are trying to create two views for our MVC app. Mobile and Web

These were the two links we followed

  1. Handling routing for both Desktop & Mobile Controllers in one instance of ASP.NET MVC
  2. Mixing ASP.NET MVC Display Mode Providers and Routing Rules

Created Account/Login.cshtml page and Account/Login.Mobile.cshtml page (with different layouts). Created a default route

routes.MapRoute(
   name: "DefaultMobile",
   url: "mobile/{controller}/{action}/{id}",
   defaults: new
             {
                 mobile = true,
                 controller = "Home",
                 action = "Index",
                 id = UrlParameter.Optional
             }
);

But the problem is that we are using routes.MapMvcAttributeRoutes(); and generating urls like \login. Is there a way to force mobile/login to fetch mobile view. something that force the Routing to display mobile view if the url starts with '/mobile/'?

Or is there another way to do it?

1
if you're going to always use mobile in your url, you can just create an area called mobile that will always be at http://siteurl/mobile/ - JamieD77

1 Answers

1
votes

You should be able to specify 2 route definitions with attribute routing as well, one for normal login and one for mobile

[Route("{type}/Login")]
[Route("Login")]
public ActionResult Login(string type = "")
{
    var isMobile = String.Equals(type,"mobile",StringComparison.OrdinalIgnoreCase);

   // to do : Return something
}