Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Dan Comperini
PLUS
Dan Comperini
Courses Plus Student 2,215 Points

Default Routes

From the "Updating the Default Route" video:

Creating our default route, why do we use controller = "ComicBooks" when our controller name is “ComicBooksController”? Is "ComicBooks" an instantiated copy of “ComicBooksController”? See code below.

routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "ComicBooks", action = "Index", id = UrlParameter.Optional} );

3 Answers

Steven Parker
Steven Parker
231,184 Points

This controller isn't the actual name of the controller.

Its the string that will appear in the first part of the URL Here you're just defining how to construct the default URL for routing purposes. It's typical for component part names to be omitted from these strings.

Rune Andreas Nielsen
Rune Andreas Nielsen
5,354 Points

Hi, Dan.

In ASP.NET MVC when you configure your route, the standard syntax is to not include the "Controller" prefix of the class name. The main reason for this I would assume is for the developer to type less.

In the end, when the ASP.NET MVC framework is looking to map the route when a request comes in, it would look for all the classes that inherit from the "Controller" class and search for a name matching "ComicBooksController" in your route setup.

I hope this helps.

Dan Comperini
PLUS
Dan Comperini
Courses Plus Student 2,215 Points

Ah, thanks for the quick replies. Both answers make sense.