tags:

views:

20

answers:

2

I have a route

       routes.MapRoute("BuildingProject", "BuildingProject/{action}/{id}", new { controller = "Home", action = "Index", id = "" });

i want it to behave like default route ie for url that starts with BuildingProject like http://localhost:4030/BuildingProject/DeleteAll. I tried

routes.MapRoute("BuildingProject", "BuildingProject/{action}/{id}", new { controller = "Home", action = "", id = "" });  

It worked.But on typing localhost:4030/BuildingProject it is not redirecting to it's Index but showing error.
.How to do this.

A: 

Try this:

 routes.MapRoute("BuildingProject", "BuildingProject/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
lulhuh
sorru but it did not work.
andrew Sullivan
Do you want all urls point to the same action? Then you can try this code: routes.MapRoute(null, "BuildingProject/{*catchall}", new { controller = "Home", action = "Index" });
lulhuh
A: 

If your routes look like this:

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

    routes.MapRoute(
        "BuildingProject", 
        "BuildingProject/{action}/{id}", 
        new 
        { 
            controller = "Home",
            action = "Index",
            id = UrlParameter.Optional
        }
    );
}

then http://localhost:4030/BuildingProject/DeleteAll will call the DeleteAll action on Home controller and if you navigate to http://localhost:4030/BuildingProject, the Index action will be invoked on the same controller.

Darin Dimitrov