【发布时间】:2020-05-22 15:31:30
【问题描述】:
我有一个 MVC 5 项目,我在旧版本的 Visual Studio 中创建并在 VS2019 中打开。它符合要求,但我的视图页面看到来自 IEnumerable(of T) 的模型的错误。例如,If Model.Count > 0 Then 告诉我“Count”不是 IEnumerable(of T) 的成员。此外,Model.FirstorDefault 给出了同样的错误。我尝试在 NuGet 中更新包,但没有成功。我在这里想念什么?这是一个在 VS2019 中打开之前完全有效且有效的项目。
我已将代码缩写为有问题的模型
回购:
Public Function GetFilesByTagID(ByVal tagID As Integer) As IEnumerable(Of File)
Dim Files As IEnumerable(Of File)
Files = From p In archiveDB.Files
Where p.Tags.Any(Function(t) t.TagID = tagID)
Select p
Return Files
End Function
控制器:
Private ar As New ArchiveRepository
Function Index(ByVal tagID As Integer) as ActionResult
Return View(ar.GetFilesByTagID(tagID))
End Function
剃刀页面:
@Modeltype IEnumerable(Of Intranet.File)
<h2>
Archives
@If Model IsNot Nothing Then
If Model.Count > 0 Then
@<small>
@Model.FirstOrDefault.Tags.Where(Function(t) t.TagID = CInt(Request.QueryString("tagID"))).FirstOrDefault.Name
</small>
End If
End If
</h2>
【问题讨论】:
-
您能否提供您的剃须刀页面的代码以及该页面使用的操作方法?
-
IEnumerable<T>没有Count属性。通过 Linq,它有一个名为Count()的扩展方法。如果FirstOrDefault()给出了同样的错误,那么你的System.Linq在你的项目中注册有问题。 -
我已经添加了一些代码 - 目前运行良好。但现在我需要进行一些编辑,并且必须使用 VS2019。
标签: asp.net .net asp.net-mvc visual-studio razor