从两个表详细信息显示WebGrid中的记录 [英] Display Records in WebGrid from Two Tables Details

查看:42
本文介绍了从两个表详细信息显示WebGrid中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友



这些是我的模特课



公共部分课程tbl_staticfielddetails

{

public Nullable< int> systemid {get;组; }

public string fieldname {get;组; }

需要公共字符串{get;组; }

public string predefinedvalue {get;组; }

public string fieldpattern {get;组; }

public string errormsg {get;组; }

public string minimum {get;组; }

public string maximum {get;组; } $ / $
public int fieldorder {get;组; }

public string tooltype {get;组; } $ / $
公共字符串数据类型{get;组; } $ / $
public string disptype {get;组; }

public int id {get;组; }

公共字符串状态{get;组; }

公共字符串标签{get;组; }

public string instructuser {get;组; }

}



公共部分课程tbl_student

{

public int Stud_id {get;组; }

public int institutionid {get;组; }

public string firstname {get;组; }

public string middlename {get;组; }

public string lastname {get;组; }

公共字符串studentimage {get;组; }

public Nullable< long> admissionnumber {get;组; }

public string admissionforclass {get;组; }

public Nullable< system.datetime> dateofadmission {get;组; }

public Nullable< long> boardregisternumber {get;组; }

public Nullable< system.datetime> dateofbirth {get;组; }

public string gender {get;组; }

public string isactive {get;组; }



}



以下是与模特相对应的两张桌子。



http://sqldiscussion.com/wp-content/ uploads / 2014/08 / WebGrid-Image.png [ ^ ]



请参考图片



i want在webgrid中显示表2记录



但它的列标题是从表1的标签字段中提取的。



我的要求是如何设计模型类以及控制器方法以在webgrid中显示记录。



提前感谢。

解决方案

构建一个包含两者的ViewModel。您可以从控制器中的存储库中提取两者,并使用对象的构造函数重载。



然后返回List< myviewmodel>并建立一个网格。





  public   class  MyViewModel 
{
public tbl_student Student {获得; set ; }

// 所需的任何标签属性

public MyViewModel(tbl_staticfielddetails details,tbl_student student)
{
Student = student;
// 从详细信息中设置适当的属性
}
}


hi Nathan Minier,



i得到答案。



感谢您的回复。



http://forums.asp.net/t/2000875.aspx?Problem+Display+Records+在+的WebGrid

hi friends

these are my model classes

public partial class tbl_staticfielddetails
{
public Nullable<int> institutionid { get; set; }
public string fieldname { get; set; }
public string required { get; set; }
public string predefinedvalue { get; set; }
public string fieldpattern { get; set; }
public string errormsg { get; set; }
public string minimum { get; set; }
public string maximum { get; set; }
public int fieldorder { get; set; }
public string tooltype { get; set; }
public string datatype { get; set; }
public string disptype { get; set; }
public int id { get; set; }
public string status { get; set; }
public string label { get; set; }
public string instructuser { get; set; }
}

public partial class tbl_student
{
public int Stud_id { get; set; }
public int institutionid { get; set; }
public string firstname { get; set; }
public string middlename { get; set; }
public string lastname { get; set; }
public string studentimage { get; set; }
public Nullable<long> admissionnumber { get; set; }
public string admissionforclass { get; set; }
public Nullable<system.datetime> dateofadmission { get; set; }
public Nullable<long> boardregisternumber { get; set; }
public Nullable<system.datetime> dateofbirth { get; set; }
public string gender { get; set; }
public string isactive { get; set; }

}

below are two tables corresponding to models.

http://sqldiscussion.com/wp-content/uploads/2014/08/WebGrid-Image.png[^]

please refer the image

i want to display table 2 records in webgrid

but its column header is refered from table 1's label field.

my requirement is how to design the model class as well as controller method to display records in webgrid .

thanks in advance.

解决方案

Build a ViewModel that incorporates the two. You can pull both from your repository in the controller and use a constructor overload for the objects.

Then just return List<myviewmodel> and build a grid from that.


public class MyViewModel
{
    public tbl_student Student { get; set; }

    //any label properties needed

    public MyViewModel(tbl_staticfielddetails details, tbl_student student)
    {
        Student = student;
        //set appropriate properties from details
    }
}


hi Nathan Minier,

i got the answer.

thanks for your reply.

http://forums.asp.net/t/2000875.aspx?Problem+Display+Records+in+Webgrid


这篇关于从两个表详细信息显示WebGrid中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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