ASP. NET core development-MVC using the dotnet command to create a controller and view

Source: Internet
Author: User
Tags dotnet

Use the dotnet command to create a controller and view in ASP. NET Core MVC, previously explained by using Yo to create a controller and view.

Here's a look at the dotnet command to create a controller and view, which is more powerful and more complete.

Combining vs Code Enables you to develop ASP. NET Core MVC in a better and faster cross-platform.

You can also better develop ASP. NET Core applications in Linux and Mac.

Creating an ASP. NET Core Application
new -t webdotnet restoredotnet run

Once created, let's add the controller and view.

The dotnet command created using is: dotnet aspnet-codegenerator

Create Controller1. Blank Controller
dotnet aspnet-codegenerator controller-name Linezero-outdir Controllers
2. Modify Controller
dotnet aspnet-codegenerator controller-name Linezero-actions-outdir Controllers

Command Add one:-actions

3. Adding and deleting +ef Controller

Generate and delete the action and corresponding view of the change.

dotnet aspnet-codegenerator controller-name linezerocontroller-m applicationuser-dc applicationdbcontext-outdir Controllers

-M refers to model

-DC refers to DbContext

4.API Controller
dotnet aspnet-codegenerator controller-name linezerocontroller-m applicationuser-dc applicationdbcontext-api-outdir Controllers

Adding a-API means generating an API controller

For more commands, refer to help:dotnet aspnet-codegenerator Controller-?

CREATE view

1. Create a View

What action can be specified, create| Edit| delete| details| List, must fill in the corresponding model

dotnet aspnet-codegenerator View Index list-m applicationuser-f-outdir Views\linezero

Here we create a name: The Index action is: List view

-F Overwrite the file if the file exists. dotnet Aspnet-codegenerator The file is not overwritten by default.

More commands can be found in Help:dotnet aspnet-codegenerator view-?

The display of this command will be finished.

dotnet Aspnet-codegenerator Source

So where does this command come from? dotnet default is no aspnet-codegenerator

The dependencies node is added as follows:

  "Dependencies": {    ...    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {      "version":"1.0.0-preview2-final",      "type":"Build"    },    "MICROSOFT.VISUALSTUDIO.WEB.CODEGENERATORS.MVC": {      "version":"1.0.0-preview2-final",      "type":"Build"    }  },

Then add the following in the Tools node:

  "Tools": {    ...    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {      "version":"1.0.0-preview2-final",      "Imports": [        "Portable-net45+win8"      ]    }  },

dotnet Restore

This makes it possible to use dotnet aspnet-codegenerator.

The Web project created above dotnet new can use dotnet Aspnet-codegenerator because the project has already added the corresponding nodes and references to us by default.

If you are developing with VS 2015 under Windows, you will get a better experience.

Using vs 2015 to open a project with dotnet Aspnet-codegenerator, vs automatically expands and adds additional functionality.

In the Project right button will find more add controller, in the Views folder right-click, will add a view.

Choose to add different types of controllers later, which is actually called the dotnet aspnet-codegenerator command.

If you think this article is helpful to you, please click " recommend ", thank you.

ASP. NET core development-MVC using the dotnet command to create a controller and view

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.