3

I have a "HomeController" and my route is like this

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

I want url be like "web-design/Index" instead of "Home/Index".
how can i do that ?
thanks

0

2 Answers 2

4

I would do it like this:

  // add a new route
  routes.MapRoute(
        name: "homepage",
        url: "web-design/{action}",
        defaults: new { 
        controller = "Home", action ="Index"
        }   
    );

  // add your default route but change the default action or controller
  routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { 
        controller = "Home", action ="SomeotherAction", id =    UrlParameter.Optional
        }   
    );
0
1

If you want "web-design/Index" to be the default route:

routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { 
        controller = "web-design", action ="Index", id =  UrlParameter.Optional
        }   
    );
1
  • i cant name a controller "web-design" , what can i do about this? Commented Mar 20, 2015 at 8:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.