0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

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

1 Comment

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" });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.