ASP.NET Core controllers
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
Defining the Home controller's actions
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(); ...
Get C# 6 and .NET Core 1.0: Modern Cross-Platform Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.