Follow these steps to install the NuGet
package of ASP.NET MVC:
MVC
and you'll get the Microsoft.AspNet.MVC package, as shown in the following result, and click on the Install button on the right-hand side:
The NuGet Package Manager will download and install the ASP.NET Core and will update the project.json
file and the associated references.
Now, your project.json
file will have updated dependencies. The second line Microsoft.AspNet.Mvc
is added:
"dependencies": { "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc": "6.0.0-rc1-final", "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final" },
Alternatively, you can also update the project.json
with the NuGet
package along with the version information. The NuGet Package Manager will automatically download and install them.
ASP.NET Core is installed in our application. Now, we need to tell our application to use ASP.NET MVC.
This needs a couple of changes to the Startup.cs
file:
ConfigureServices
method of the Startup
class:services.AddMvc();
Configure
method of the Startup.cs
file:app.UseMvc(routes => { app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
In the preceding statement, we are configuring the routes for our application.
In this chapter and most of the chapters in this book, we will write codes manually or choose an Empty template instead of relying on scaffolding templates. For those who are new to the term scaffolding, scaffolding is a feature that generates all the necessary boilerplate code for you for the selected item (for example, the Controller) instead of you needing to write everything. Though I agree that scaffolding templates are useful and save time in generating the boilerplate code, they hide many of the details that beginners have to understand. Once you write code manually, you'll know all the intricacies of how each of the components is contributing to the big picture. Once you are strong in the fundamentals, you can use scaffolding templates to save you time in writing the boilerplate code.