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
dotnet 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.
Core development-MVC using the dotnet command to create a controller and view