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 trialshawn007
15,408 PointsHow does ComicBooks get picked up in the url?
How does ComicBooks get picked up in the url when the class is called ComicBooksController?
5 Answers
Steven Parker
231,268 PointsThe routing determines the code to use from the URL.
The first part of the URL after the site name indicates the controller. The routing looks for a controller module with that name and "Controller" added to it.
The next part of the URL indicates the action. The routing will then look for a method inside the controller that has that name.
Juan Emmanuel Afable
18,531 PointsGot it! I think it was just an spelling error. Thanks for the help!
Juan Emmanuel Afable
18,531 PointsI am currently using VS 2017 and i am having issues viewing the web page when i compile the same code. Is there something that has changed in the naming conventions of Controllers for VS 2017? I still get the same 404 error when i change the directory to add /ComicBooks/Detail
Michael Lauridsen
10,321 PointsHi Juan,
It should still work. In fact I just tested it, and it does.
Are you sure you named your controller "ComicBooksController" and your method "Detail"? It might be a simple spelling error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace ComicBookGallery.Controllers
{
public class ComicBooksController : Controller
{
public string Detail()
{
return "Hello world from the comic books controller!";
}
}
}
Eric Ridolfi
19,417 PointsWhy do you need the word "controller" in the class name. I know he mentioned that you need it so .net knows it's a controller but wouldn't the inheritance from the Controller class tell it that?
Kevin Gates
15,053 PointsMy guess: it may be an efficiency thing. Faster for a computer to scan the names of files versus scanning the inside of all the documents to find a class that happens to inherit from Controller.
kevin hudson
Courses Plus Student 11,987 PointsI just asked this question in the last video but It's not clear to me - So I'm understanding it this way if I make a controller called ILoveApplesController that points to the Base Controller then my URL would be /iloveapples/detail ? and this happens because the program is looking for the controller name with the "Controller " name added to it with no spaces?
shawn007
15,408 Pointsshawn007
15,408 PointsThanks for the help.