Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In refactoring a lot of MVC code, I have run into an issue with my URL design. For example, let's say we have a Venue object

public class Venue 
    public long ID { get; set; }
    public List<Event> Events { get; set; }

and an Event object

public class Event
    public long ID { get; set; }
    public Venue Venue { get; set; }

So my initial set up was to have an action set up in the EventController like

public ActionResult List (long? ID) //

where the ID specified the Venue, so it would return a list of events for that venue. If an ID is not specified, it returns a list of all events. This results in a confusing URL, because the ID parameter is ambiguous and misleading.

I then thought to change it to

public ActionResult List (long? VenueID) //

which makes a lot more sense and is more clear.

An even cleaner URL would exist if the action was moved to the VenueController and set up like

public ActionResult Events (long? ID) //

as the ID would clearly specify the Venue's ID. The issue with this URL is that you are primarily dealing with Event objects in the VenueController, which seems wrong.

I have been leaning towards the first option ( because, even though the other option is cleaner, it seems like I should keep the Event pages (as I view this List page as more related to the Event object) in the EventController. Any recommendations?

share|improve this question
up vote 3 down vote accepted

Your best answer is going to be: Decide what you want it to look like, then modify the routing to match.

You can customize how the routing engine processes URLs. See here for examples. Our website uses MVC, but you wouldn't be able to tell it from the URLs.

In your specific case, I'd suggest making a route which looks for the pattern "Venue/{id}/Events" and routes it to the Event controller.

share|improve this answer
You might even customize the router to redirect{id}/Events to{id} and offer both URIs. – Bart van Ingen Schenau May 6 '13 at 17:15
I hadn't thought about dealing with it using routing. Thanks. – gwely May 6 '13 at 17:35
@theyshookhands - Yeah, changing the routing isn't an intuitive part of working with MVC, since all the tutorials and examples assume the standard Controller/Action/ID format. But it's powerful. Glad it helped! – Bobson May 6 '13 at 18:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.