Quick start to configure ASP.NET Core Mvc

Microsoft recently released its next generation platform ASP.NET Core 1.0. ASP.NET Core is a significant redesign of ASP.NET. ASP.NET Core is an open source, lightweight and cross platform application development platform. ASP.NET Core apps can run on .NET Core or on the full .NET Framework. You can develop and run your ASP.NET Core apps cross-platform on Windows, Mac and Linux.

In previous version, Web API and MVC are almost same(except one or two). Shailendra Chauhan had explained meaningful difference between MVC and Web.API on his blog dotnet-tricks. Until now, in MVC5 we are facing issues with assemblies, Web API belong to System.Net.Http assembly and MVC belongs to System.Web.MVC. But in ASP.NET Core Microsoft makes it common assembly Microsoft.AspNetCore.Mvc for both. In this post we are going to cover basic configuration to add MVC in ASP.NET Core project manually.

By default, empty template project will include only required components. The new project structure is different than previous and includes new files like project.json, Startup.cs, wwwroot, global.json and Program.cs.

Just like previous MVC versions, to setting up MVC in a project we need to create Controllers, Models and Views folders.

It's not enough yet! In ASP.NET Core application we need to register MVC middleware. First though, you need to add the correct NuGet packages, so open your project.json file and add the following dependencies:

After adding MVC in project.json file, Visual Studio will automatically start restoring the package in the project. References section will look like,

Configure the Application Pipeline

In ASP.NET Core you can compose your request pipeline using Middleware. ASP.NET Core middleware performs asynchronous logic on an HttpContext and then either invokes the next middleware in the sequence or terminates the request directly.

Configure defines the middleware in the request. By default ASP.NET Core doesn't provide any pre-configured route mapping mechanism for MVC. UseMvc extension method will use to map Route in application.

Add Controller

In Visual Studio right click on "Controllers" folder, select MVC Controller class and name it "HomeController".

Visual Studio will create HomeController with default Index action. Next, we will define and initialize the List<string>(). Add some fruit names in the list and pass it in to the return View() statement.