C# 无法使用模型中的razor foreach

C# 无法使用模型中的razor foreach,c#,asp.net-mvc,razor-2,C#,Asp.net Mvc,Razor 2,你好 我有这个模型 public class ProjectTypeViewModel { public string CategoryName{ get; set; } public IEnumerable<ProjectType> Tipo { get; set; } } public class ProjectType { [Required] public Guid Id { get; set; } [MaxLength(5

你好

我有这个模型

public class ProjectTypeViewModel
{      
    public string CategoryName{ get; set; }
    public IEnumerable<ProjectType> Tipo { get; set; }
}
public class ProjectType
{
    [Required]
    public Guid Id { get; set; }
    [MaxLength(512)]
    [Required]
    public string Type{ get; set; }
    [Required]
    public string AddedBy { get; set; }
    public Category Category{ get; set; }
    public Guid? CategoryId{ get; set; }

}
公共类项目类型视图模型
{      
公共字符串CategoryName{get;set;}
公共IEnumerable Tipo{get;set;}
}
公共类项目类型
{
[必需]
公共Guid Id{get;set;}
[MaxLength(512)]
[必需]
公共字符串类型{get;set;}
[必需]
由{get;set;}添加的公共字符串
公共类别{get;set;}
公共Guid?CategoryId{get;set;}
}
我想将ProjectTypeViewModel返回到我的视图中

@model  List<MyProject.ViewModels.ProjectTypeViewModel>
@foreach(var tipo in Model )
{

}
@型号列表
@foreach(模型中的var tipo)
{
}
我这里有一个问题,我的模型显示以下错误:

foreach语句不能在类型为的变量中操作 ProjectTypeViewModel,因为不包含 GetEnumerator

我做错了什么


谢谢

您需要访问以下型号中的列表

@model  MyProject.ViewModels.ProjectTypeViewModel
@foreach(var tipo in Model.Tipo)
{

}

您是否可以将创建模型并传递到视图的控制器代码共享?您是在运行时还是编译时遇到这个错误的?非常感谢您花时间。我已经解决了这个问题,我在写我的观点时遇到了错误。我只需要使用IEnumerable