1

I have a controller called CarController located in a folder called Buy. So the url becomes www.website.com/Buy/Car

How do I make the url be instead "/purchase/vehicle" without changing controller and folder name?

Thanks!

2
  • routes.MapRoute("buyCar", "purchase/vehicle", new { controller = "Car", action = "Buy" }); Commented Dec 29, 2013 at 17:03
  • The folder doesn't matter. Physical folder structures do no relate to routes. Commented Dec 29, 2013 at 17:03

2 Answers 2

3

You need to define a new route for it

    routes.MapRoute(
        name: "VehicleRoute",
        url: "purchase/vehicle",
        defaults: new { controller = "Car", action = "TheAction" }
    );

Just make sure you have placed it before the default route.

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

Comments

2

You can do this with a custom route. See here for informations about routing. You can then create your custom route with default values for the Controller and the action, something like:

routes.MapRoute(
  "MyRoute",
  "purchase/vehicle",
  defaults: new { controller = "Car", action = "Buy" }
);

You have to put in there the correct controller name and the action you want to call.

Comments

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.