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.

Note

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 ...

Get C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition 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.