Now that ASP.NET Core MVC knows the name 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
client as an HTTP response
To return the results from the view to the client as an HTTP responseDefining the Home controller's actions
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(); } &...