Asp.net mvc MVC视图页面未显示值

Asp.net mvc MVC视图页面未显示值,asp.net-mvc,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 4,我的模型课如下: 我有三个班,其中两个是部分班,一个是简单班 [MetadataType(typeof(RegistrationMetaData))] public partial class Registration { } public class RegistrationMetaData { public string Id { get; set; } public string Name { get; set; } p

我的模型课如下: 我有三个班,其中两个是部分班,一个是简单班

[MetadataType(typeof(RegistrationMetaData))]
public partial class Registration
{              
}

public class RegistrationMetaData
{
    public string Id { get; set; }        
    public string Name { get; set; }
    public string Username { get; set; }
    public virtual ICollection<Images> Images { get; set; }
}

[MetadataType(typeof(ImagesMetaData))]
public partial class Images
{
}

public class ImagesMetaData
{
    public string id { get; set; }
    public string stuid { get; set; }
    public string stuimg1 { get; set; }               
    public virtual ICollection<Registration> Registrations { get; set; }
}

public class EmployeeViewModel
{
    public string Name { get; set; }
    public string stuimg1 { get; set; }                  
}

public class NotificationViewModel
{
    public Registration registration { get; set; }
    public Notification notification { get; set; }        
    public IEnumerable<EmployeeViewModel> EmployeeViewModel { get; set; }
    public Images images { get; set; }
}
[MetadataType(typeof(RegistrationMetaData))]
公开部分类别注册
{              
}
公共类注册元数据
{
公共字符串Id{get;set;}
公共字符串名称{get;set;}
公共字符串用户名{get;set;}
公共虚拟ICollection映像{get;set;}
}
[元数据类型(typeof(ImagesMetaData))]
公共部分类图像
{
}
公共类ImagesMetaData
{
公共字符串id{get;set;}
公共字符串stuid{get;set;}
公共字符串stuimg1{get;set;}
公共虚拟ICollection注册{get;set;}
}
公共类EmployeeViewModel
{
公共字符串名称{get;set;}
公共字符串stuimg1{get;set;}
}
公共类NotificationViewModel
{
公共注册{get;set;}
公共通知{get;set;}
公共IEnumerable EmployeeViewModel{get;set;}
公共图像图像{get;set;}
}
然后,我在控制器类中使用了下面的代码来获取注册表中带有外键的图像记录

IEnumerable<EmployeeViewModel> model1 = null;
model1 = (from e in db.Registrations  
          join j in db.Images on e.Id equals j.stuid  
          where e.Email == Email  
          select new EmployeeViewModel  
          {  
              Name = e.Name,  
              stuimg1 = j.stuimg1                                    
          }).ToList();  


var mixmodel = new NotificationViewModel  
{  
    EmployeeViewModel = model1  
};  

return View(mixmodel);  
IEnumerable model1=null;
model1=(从数据库注册中的e开始)
将j加入e.Id上的db.Images等于j.stuid
其中e.Email==电子邮件
选择新建EmployeeViewModel
{  
Name=e.Name,
stuimg1=j.stuimg1
}).ToList();
var mixmodel=新的NotificationViewModel
{  
EmployeeViewModel=model1
};  
返回视图(mixmodel);
至少我的查看页面如下所示:-

@model IEnumerable<Amar.Models.NotificationViewModel>  

@foreach (var item in Model)  
{  
    @item.EmployeeViewModel.stuimg1            
}  
@model IEnumerable
@foreach(模型中的var项目)
{  
@item.EmployeeViewModel.stuimg1
}  
但是我犯了个错误

System.Collections.Generic.IEnumerable“”不包含“stuimg1”的定义,并且找不到接受类型为“System.Collections.Generic.IEnumerable”的第一个参数的扩展方法“stuimg1”(是否缺少using指令或程序集引用?)

我已经通过调试我的代码是好的,直到控制器页面…但从查看页面的值没有显示。我认为有一些小错误,我已经犯了

请有人帮帮我,我从两个星期以来一直在努力解决这个问题

我想从同一个视图页上的另一个类中获取数据,这就是我使用NotificationViewModel类的原因

return View(mixmodel);
您的视图需要一种类型为
IEnumerable
,但mixmodel只是一种
NotificationViewModel

我看不出您通过使用这个额外的类“NotificationViewModel”实现了什么。如果您的视图被更改为期望一个
IEnumerable
,您可以直接传入model1

然后,您可以将视图更改为:

@foreach (var item in Model)  
{  
    @item.stuimg1            
}  

如果视图的其他部分确实需要这个额外的抽象层,那么您需要坐下来思考什么是单个实例,什么是列表。如果您遇到问题,请尝试绘制它。

谢谢Chris…事实上,我希望在同一个视图页上还有其他类,这就是为什么..我正在添加NotificationViewModel类。请给出任何想法..因为我的大脑被阻塞了。。。