Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# ASP.NET MVC Basics Modeling and Presenting Data Updating the Controller

Still receiving parameter error after casting the id parameter

During the video. I added id.Value to make id an explicit cast so the website will not throw an error. However, it still does. Here is my source code.

(Disregard WebApplication1, that is the name that I've been using for the namespace as I can't figure out how to delete the original one that I messed up on before.

using WebApplication1.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using WebApplication1.Data;

namespace WebApplication1.Controllers { public class ComicBooksController : Controller {

    private ComicBookRepository _comicBookRepository = null;

    public ComicBooksController()
    {
        _comicBookRepository = new ComicBookRepository();
    }
    public ActionResult Detail(int? id)
    {
        if (id == null)
        {
            return HttpNotFound();
        }
        var comicBook = _comicBookRepository.GetComicBook(id.Value);

        return View(comicBook);

    }
}

}

1 Answer

Steven Parker
Steven Parker
220,634 Points

For those of us who don't happen to be working on the same project, it helps if you make a snapshot of your workspace and post the link to it here.