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# ASP.NET MVC Basics Controllers Using Action Result Types

Aaron Selonke
Aaron Selonke
10,323 Points

MVC ComicGallery Broke when swtiching to the ContentResult action method

Followed line by line when switching the Detail fucntion to an action method, but the site broke afterward. Getting the 404 error.

Here are the two screenshots of the code from the IDE and the 404 error in the browser, What did I miss? http://uploadpie.com/sOAg8 http://uploadpie.com/zNx33

Thanks in advance

2 Answers

Dom Talbot
Dom Talbot
7,686 Points

Hi Aaron

I think it might be because your ComicBookController class isn't set to public.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace ComicBookGallery.Controllers
{
    public class ComicBooksController : Controller
    {
        public ContentResult Detail()
        {
            return new ContentResults()
            {
                Content = "Hello from the comic books Controller"
            }
        }
    }
}
Aaron Selonke
Aaron Selonke
10,323 Points

Yes that was it, Thanks.

Follow up question is that in the file path http://localhost:53286/ComicBooks/Detail Controller = ComicBooks Action = Detail

The routing process knows that the controller is /ComicBooks/ because the class name ComicBooksController? Is that correct?

That is correct. As long as you follow the controllerNameController pattern, MVC will automatically associate the /controllerName/ route with that controller.