This article is based on the comparison, mainly to show you how to create an ASP. NET 5 project, mainly includes the following:
Open Visual Studio Preview. Select the "File" menu and choose New > Project.
In the New Project dialog box, click Templates > Visual C # > Web, select the ASP. NET Web Application project template. Name the project "ToDoList" and click OK.
Add TODO Controller
1. Download the complete project completed project.
2. In the Project Solution Manager, right-click the Controllers folder > Add > Exiting Item. enter the path to the TodoController.cs file in the download Project .
3. Use the same method to add the models\todoitem.cs and models\todoitemeditmodel.cs files to the Models folder.
4. Create a ToDo folder under Views. Using the same method, add all the view files under the Views\todo folder to the Views\todo folder.
5. Change the ActionLink call Todo controller under the views\shared\_layout.cshtml file:
<! DOCTYPE Html>
6. Add DbSet containing the Todoitem model to the models\identitymodels.cs file.
applicationdbcontext:identitydbcontext<applicationuser> _created = dbset<todoitem> TodoItems {;}
7. Click the Todo app link to run the app. You will encounter the following error message (This problem will be resolved in a later article).
A database operation failed while processing the request.
Sqlexception:invalid object name ' TodoItem '.
There is pending model changes for Applicationdbcontext
Scaffold a new migration for these changes and apply them to the database from the command line
> K EF Migration Add [migration name]
> K EF Migration apply
Install K Version Manager (KVM)
1. Run the Visual Studio Command prompt tool as an administrator.
2. Execute the following command:
@powershell-noprofile-executionpolicy Unrestricted-command "IEX (New-object net.webclient). Downloadstring (' Https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.ps1 ')) "
The above instructions will install KVM for the current user.
3. exit The Visual Studio Command prompt tool and re-run the Visual Studio Command prompt tool with administrator (you need to use the new command prompt tool to get the updated path environment).
4. Upgrade KVM with the following command:
KVM Upgrade
Now it's ready to run EF migration:
Performing EF Migrations
1. In the administrator command prompt form, change the current action path to the project folder, which contains the Project.json file under the project folder.
2. Run the following directives in the command prompt form:
k EF Migration Add Initial
K EF Migration Apply
EF Migration Add Initial
The directive will add a migration file in the form <date>_<migration Name>.cs, and the migration file contains the migration code that adds the TodoItem DbSet. Themigrations\applicationdbcontextmodelsnapshot.cs file is updated to include instructions to create Thetodoitem entity.
Builder. Entity (, b =><> (<> (<> (<> (
· Run the app and click the Todo app link. Create a new Todo item by clicking on the creation new todo link.
About the TODO controller
The Todo controller is similar to creating an ASP. NET MVC 5 project with an exception. In this example, the data content is injected into the Todo controller. You can learn more from the link: Dependency injection in ASP. VNext.
The above steps create a new ASP. NET 5.0 project, and in the next article we will describe how to use the view components. Please look forward to it.
Original address: View components and Inject in ASP 6
ASP. 5 Series Tutorial (ii): Hello World