Controllers

We will build a comic book gallery.

One of the main features is the ability to view the details for a specific comic book. Let's make it.

  1. In solution explorer, right-click on controller folder > Add > Class
  2. Name it "ComicBooksController".
  3. Because our code inherit from Base Controller class, we need to type: Controller besides the public class code.
  4. Fix the error.
  5. Now, we need to create a method from controller. Name it with Detail()
    public class ComicBooksController : Controller
    {
        public string Detail()
        {
            return "Hello from ComicBookController";
        }
    }
    
  6. Run on your browser. Still get an error? add the URL with path/ComicBooks/Detail
  7. Try change the public class to private class.
  8. Controller class needs to be public. Otherwise, MVC won't be able to find and use them.

results matching ""

    No results matching ""