如何创建多个表的列表并在单个视图中显示 [英] How To create the List of multiple table and display it in single View

查看:83
本文介绍了如何创建多个表的列表并在单个视图中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包装器类,其中包含两个表的对象以及数据库上下文

I have a wrapper class which contains the object of two tables and there DB context

public class StudentInfo
   {
          public StudentPersonalInfo PersonalInfo { get; set; }
          public EducationQualification EducationalQualification { get; set; }
    }

     public class StudentDbContext:DbContext
    {
public DbSet<StudentPersonalInfo> StudentPersonalInfos { get; set; }
public DbSet<EducationQualification> EducationQualifications { get; set; }
    }



现在,在Controller中,我创建了StudentInfo类的列表并传递该类对象,并将其添加到列表中,如下所示,



Now in Controller I have create the List of StudentInfo class and pass that class objectand add them in list Like this,

// GET: /StudInfo/
        public ActionResult Index1()
        {
           List<StudentInfo>sti = new List<StudentInfo>();

           StudentInfo temp = new StudentInfo();
           temp.PersonalInfo = new StudentPersonalInfo();
           temp.EducationalQualification = new EducationQualification();
            sti.Add(temp);


        }


现在,我想在上下文中添加它,但不知道如何操作,所以请告诉我如何执行此操作,然后尝试在视图中显示列表.
请帮助


Now I wanted to add it in context and don’t know how to doo it, so please tell me how to do this and hoe to display the list in view.
Please help

推荐答案


基本上,该技术称为元组.现在,您需要添加一个视图,并将该视图强类型转换为"StudentInfo"模型.现在,一旦您在视图中完成了该操作,就可以像
一样使用它
StudentInfo.PersonalInfo和StudentInfo.EducationalQualificatio作为两个不同的模型集.

看这个例子
MVC与Ajax-初学者入门(第3部分)

在后面的部分中,我已经对此进行了解释.
Hi
Basically this technique is known as tuple. Now you need to add a view and strongoly typecast the view to ''StudentInfo'' model. Now once you did that in view itself, you can use it like

StudentInfo.PersonalInfo And StudentInfo.EducationalQualificatio as two different model set.

Look at this example
MVC With Ajax - Push Start For Beginners(Part - 3)

In the later part, i have explained this.


这篇关于如何创建多个表的列表并在单个视图中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆