1

I'm not even sure I know the right terminology to articulate this correctly. I'm new to MVC and have inherited a partially complete project.

The project uses Areas, I don't understand MVC and routing enough to resolve the following:

I have a site eg "www.b2c.com" and have an area "OnlineOrder" controller "Home" and view "Index". I want visitors to go to by default when they enter the url "http://www.b2c.com" --> OnlineOrder/Home/Index the url "http://www.b2c.com/OnlineOrder/Home/Index" works fine.

My RouteConfig file contains:

   public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
            "Default_Home", // Route name
            "",        // URL with parameters
            new { controller = "Home", action = "Index" }// Parameter defaults

      );

And I have a area registration file in the root folder of the area:

public class OnlineOrderAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "OnlineOrder";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(

                        name: "Info",
              url: "OnlineOrder/{controller}/Info/{action}",
              defaults: new { controller = "Home", action = "Index" }
          );
            context.MapRoute(
                name: "Default",
                url: "OnlineOrder/{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            ).DataTokens.Add("areas", "OnlineOrder");


        }
    }

Not sure what to do.

Math3w
  • 17
  • 1
  • 7
  • I have found [link](http://stackoverflow.com/questions/26160881/how-to-code-maproute-in-registerarea-to-route-the-area-default-to-another-area?rq=1) as a possible solution. I wounder if there is a way using route mapping as opposed to re-direction within a controller? – Math3w May 19 '15 at 10:06

2 Answers2

1

Add to your RouteConfig.cs file above your Default route or remove Default route.

routes.MapRoute(
    name: "Area",
    url: "",
    defaults: new { area = "OnlineOrder", controller = "Home", action = "Index", id = UrlParameter.Optional }
);

This will confirm your area is 'OnlineOrder'

public ActionResult Index()
{
    ViewBag.Message = RouteData.Values["area"];

    return View();
}

Thanks

shammelburg
  • 6,974
  • 7
  • 26
  • 34
0

you have two possible Option

  1. you can change default route
  2. Perform redirect operation in your home controllers' index action
Kaushik Thanki
  • 3,334
  • 3
  • 23
  • 50