10 minutes easy to get to know ASP. NET MVC6

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.