如何从mvc4中的多个模型获取数据?

时间:2013-11-17 09:18:39

标签: asp.net-mvc-3 asp.net-mvc-4

我的应用程序中的自定义视图中存在上载图像的问题 我有三个型号

    public int EmpId { get; set; }
    public string EmployeeName { get; set; }
    public virtual ICollection<Picture> picture{ get; set; }

和第二

    public int MacId { get; set; }
    public string machine { get; set; }

和第三

public int PicId { get; set; }
    public string PicPath { get; set; }             
    public int MacId { get; set; }
    public int EmpId { get; set; }  

    public virtual Employee Employee { get; set; }

我想让它显示mac的图片以及接受它的员工是谁?

1 个答案:

答案 0 :(得分:0)

创建新模型使用您想要绑定到视图的必要属性。

例如:

class newModelName
{
     public Model1TypeName model1 {get ; set; }
     public Model2TypeName model2 {get ; set; }
     public Model3TypeName model3 {get ; set; }
}

现在,您可以将此新模型绑定到您的视图,该视图将包含来自所有三个视图的所有必要信息。