This article explains how to develop the MVC6 application under the normal editor.
First install the MVC6 NuGet package:
You can see that you have added a MVC6 reference to the Project.json file:
1. Using middleware
in ASP. NET 5, Di is highly recommended. So. NET team has introduced a DI component (Microsoft.Framework.DependencyInjection) that can be adapted to the mainstream. NET IOC framework.
In this component, there is an extension method Addmvc () to inject the MVC controller into the container. Confirm that the MVC-related injection is complete by USEMVC ().
Modify the Startup.cs file:
2. Using the Configureservices (iservicecollection Services) method
The Configureservices (iservicecollection Services) method is called automatically by the. NET framework when the application starts. After the method call is complete, the Configure (Iapplicationbuilder app) method is called.
Then the Startpu.cs file can be modified as follows:
3. Routing
In MVC6, the default static route table is not available, and the route can be added via the USEMVC () method.
First add the reference in the Startup.cs file: using Microsoft.AspNet.Routing.
You can then add the default route by using the following method.
4. Controller
In MVC6, a big change is that the controller no longer needs to inherit that name as the base class for the controller, but in practice you may be accustomed to inheriting it, so this habit can be maintained. The MVC framework automatically searches the *controller class and considers it to be a controller.
Below we create a simple controller for us.
Re-run in the same directory as the current file: K Web
See the familiar MVC again.
10 minutes easy to get to know ASP. NET MVC6