Taking ASP.NET Core MVC further
Now that you've seen the basics of how models, views, and controllers work together to provide a web application, let's look at some common scenarios, such as passing parameters and annotating models.
Passing parameters using a route value
Back in the
HomeController class, add the following action method. It uses a class called
defaultmodelbinder to automatically match the
id passed in the route to the parameter named
id in the method.
Model binders are very powerful, and the default one does a lot for you. For advanced scenarios, you can create your own by implementing the
IModelBinder interface, but that is beyond the scope of this book.
Inside the method, we check to see whether
id is null, and if so, it returns ...