Now that MVC knows the names of the controller and action, it will look for a class that implements an interface named IController
. To simplify the requirements, Microsoft supplies a class named Controller
that your classes can inherit from.
The responsibilities of a controller are as follows:
To extract parameters from the HTTP request
To use the parameters to fetch the correct model and pass it to the correct view
To return the results from the view to the client as an HTTP response
In the
Solution Explorer window, expand the Controllers folder and double-click on the file named HomeController.cs
:
public class HomeController : Controller { public IActionResult Index() { return View(); } public IActionResult About() { ViewData["Message"] = "Your application description page."; return View(); } public IActionResult Contact() { ViewData["Message"] = "Your contact page...