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