ASP.Net Core MVC:编译错误。怎么解决?

问题描述 投票:0回答:1

在开发了一些具有排序和搜索功能的 ASP.Net Core MVC 站点之后,工作得很好,当进行分页时,我遇到了一些我不理解的错误,所以我认为开发演示应用程序是一个好主意。 好吧,我也遇到了同样的错误:奇怪,不是吗? 我想,如果演示应用程序中存在众所周知并能快速纠正的错误,那么另一个假设就是我的机器上的错误。 我希望有人能够定位错误,以避免我完全重新安装机器的痛苦,这肯定需要......至少需要一些时间。

首先,参考页面在那里:教程:添加排序、过滤和分页 - ASP.NET MVC with EF Core

在该页面上,搜索“获取代码”,然后单击“下载或查看已完成的申请”。

我很惊讶地看到一个以“Aspnet-Docs”开头的标题,但是Microsoft 的人确认了我的链接是正确的。

我到达那里: https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/data/ef-mvc/intro/samples/cu-final

然后我单击页面顶部导航栏中的“代码”,然后单击“代码”按钮。

我获得了一个“克隆”界面,它为我提供了要克隆的 URL: https://github.com/dotnet/AspNetCore.Docs.git

因此,在 Visual Studio 2022 中,我启动一个新会话,单击“克隆存储库”,然后粘贴该 URL。

在启动执行时,我没有看到任何有说服力的东西。没有出现应用程序窗口。

将 Visual Studio 2022 更新到版本 4.8.09032 后,我再次启动执行,并出现四个错误。

也许最好先从错误窗口中提供每个版本的原始(本地化)版本,然后再将其翻译为英语。

"Gravité   Code    Description Projet  Fichier Ligne   État de la suppression  Détails Erreur (active) CS0234  Le nom de type ou d'espace de noms 'Entity' n'existe pas dans l'espace de noms 'System.Data' (vous manque-t-il une référence d'assembly ?)  MVCStudents01   C:\Projects Visual Studio\Web\MVCStudents01\MVCStudents01\DAL\SchoolInitializer.cs  10      " 
错误 CS0234,命名空间“System.Data”中不存在类型名称或命名空间“Entity”。 (您是否缺少装配参考?)

"Gravité   Code    Description Projet  Fichier Ligne   État de la suppression  Détails Erreur (active) CS1503  Argument 1 : conversion impossible de 'string' en 'Microsoft.EntityFrameworkCore.DbContextOptions'  MVCStudents01   C:\Projects Visual Studio\Web\MVCStudents01\MVCStudents01\DAL\SchoolContextt.cs 11      "
错误 CS1503 参数 1:无法从“字符串”转换为“Microsoft.EntityFrameworkCode.DbContextOptions”

"Gravité   Code    Description Projet  Fichier Ligne   État de la suppression  Détails Erreur (active) CS0246  Le nom de type ou d'espace de noms 'DbModelBuilder' est introuvable (vous manque-t-il une directive using ou une référence d'assembly ?)    MVCStudents01   C:\Projects Visual Studio\Web\MVCStudents01\MVCStudents01\DAL\SchoolContextt.cs 20      "
错误 CS0246 找不到命名空间“DbModelBuilder”的类型名称(您是否缺少 using 指令或程序集引用?)

"Gravité   Code    Description Projet  Fichier Ligne   État de la suppression  Détails Erreur (active) CS0246  Le nom de type ou d'espace de noms 'PluralizingTableNameConvention' est introuvable (vous manque-t-il une directive using ou une référence d'assembly ?)    MVCStudents01   C:\Projects Visual Studio\Web\MVCStudents01\MVCStudents01\DAL\SchoolContextt.cs 22      "
错误 CS0246 找不到类型名称或命名空间“PluralizingTableNameConvention”(您是否缺少 using 指令或程序集引用?)

所以,也许经过一段距离后,我会很明显地忘记安装一些东西。可能有人会比我更快。

正如我所说,当看到代码中的错误时,我尝试克隆演示应用程序,并且至少部分看到相同的错误。

asp.net-core model-view-controller
1个回答
0
投票

https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/sort-filter-page?view=aspnetcore-8.0#add-paging-to-students-index从此链接,我们可以看到,我们首先需要使用PaginatedList.cs的CreateAsync方法来提取页面大小和页码。

相关路径可以参考:

aspnetcore/data/ef-mvc/intro/samples/cu-final/PaginatedList.cs

其次,需要在

StudentsController.cs
中配置Index方法 相关路径可以参考:

aspnetcore/data/ef-mvc/intro/samples/cu-final/Controllers/StudentsController.cs

Views/Students/Index.cshtml
中配置相关视图。相关路径是:

aspnetcore/data/ef-mvc/intro/samples/cu-final/Views/Students/Index.cshtml
© www.soinside.com 2019 - 2024. All rights reserved.