首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Asp.Net MVC 5应用程序缺少模型

Asp.Net MVC 5应用程序缺少模型
EN

Stack Overflow用户
提问于 2018-07-30 07:51:49
回答 1查看 776关注 0票数 0

我将按照以下步骤创建一个新的ASP.NET项目:

代码语言:javascript
复制
1.  Create New Project

a.  Under Visual C#, select Web 

b.  Click on ASP.NET Web Application

c.  Give project a name and location to be saved

2.  On the New ASP.NET Project window, select MVC and make sure MVC is checked under “Add folders and core references for”. Also, check the box “Add unit tests”

3.  In Solution Explorer, right-click on the Models folder, and then add a new class. This will be your first model.

4.  In the class file that you just added, give it any properties that the object may need. Remember, this model will represent a table in your database and the properties represent the columns of that table in the database.

5.  In the Models folder, click on IdentityModels.cs. Under class ApplicationDbContext, add a property of type DbSet<> i.e. DbSet<Person> Person

6.  For migrations, locate the Package Manager Console. Then type in the following commands:

a.  Enable-Migrations

b.  Add-Migration MigrationName

c.  Update-Database

7.  To add a Controller without scaffolding: 

a.  right-click on the Controllers folder and click Add  Controller. Then select “MVC 5 Controller - Empty”

b.  Give the Controller a name

c.  Notice under the Views folder there is an empty subfolder with the name you just gave your Controller

d.  Right-click on the subfolder and click Add  View. 

e.  Give the View a name i.e. Create. Then, select a View template from the drop-down list i.e. Create 

f.  Select the drop-down list for Model class. Select the Model you are creating a Controller for. Also, select the data context class you want to use. It will likely be ApplicationDbContext.

8.  To add a Controller with scaffolding: 

a.  Right-click on the Controllers folder and click Add  Controller. Then select “MVC 5 Controller with views, using Entity Framework”. This is called scaffolding. 

b.  When the Add Controller window pops up, select the drop-down list for Model class. Select the Model you are creating a Controller for. Also, select the data context class you want to use. It will likely be ApplicationDbContext. Leave all three boxes checked under the Views section. Then click “Add”.

9.  To check out your Connection String, double-click on the Web.config file in the Solution Explorer

在步骤5中,没有IdentityModels文件、AccountViewModels文件或ManageViewModels文件,就像通常的那样。我可能遗漏了什么步骤?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-30 08:18:53

在步骤2中,选择MVC后,在右窗格中,如果显示“无身份验证”,请单击“更改身份验证”,然后选择一个,从单独身份验证或windows身份验证开始。一旦你的项目创建完成,你就可以看到IdentityModel,AccountViewModel等。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51585470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档