Introduction to ASP.NET Core part 9: MVC continued with routing
February 3, 2017 Leave a comment
Introduction
In the previous post we continued our exploration of MVC in ASP.NET Core. We discussed how a controller action can return various response types that implement the IActionResult interface. The are many return types to choose from and many of them map to a standard HTTP status code like 200 OK, 201 Created etc. There are other response types such as ObjectResult that serialises the provided object using a serialiser which usually defaults to JSON. Finally we saw how to connect a controller action with a view that accepts an object. The view can use the injected object to render dynamic HTML. The default view file type in .NET Core is a Razor view with the cshtml file extension. We can mix HTML and C#-like syntax in a cshtml file. So we have managed to connect the various parts of the MVC pattern in our demo application: a URL is routed to a controller and an action method, the action method builds a model which is injected into a view and the view uses the model to build the final HTML that’s sent back to the user.
In this post we’ll take another look at routing.