3

I'm new to MVC so I'm having some issues figuring out how to set up my routes for the following scenario.

Let's say I have site that looks up flight data and show three major views for each flight.

I want to have the URL structure as follows:

www.domain.com/<flightnumber>/   <-- Main page for the flight
www.domain.com/<flightnumber>/crew  <-- A page with details of the crew for that flight
www.domain.com/<flightnumber>/destination  <-- details of the destination for the flight

So, basically the lookup key is the first item after the domain. Any subsequent part of the URL maps to a specific view for that flight.

Seems simple but I can't seem to figure out how to structure the controller and routes...

1 Answer 1

5

Try this

 routes.MapRoute(
         "YourRouteName", // Route name
         "{flightNumber}/{action}", // URL with parameters
         new { controller = "YourController", action = "YourDefaultAction", flightNumber = 0    } // Parameter defaults
        );

You should to put this at the top in RegisterRoutes method of RouteConfig.cs (MVC4) or Global.asax (MVC3)

You can read more on routing on asp.net site http://www.asp.net/mvc/tutorials/older-versions/controllers-and-routing/asp-net-mvc-routing-overview-cs

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

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.