我的問題是列表<>,我在兩個列表中控制器操作方法採取兩個模型它傳遞兩個列表中的值,但它不能傳遞兩個列表值在視圖中,我給我下面的代碼,請給一些解決方案這個。如何在mvc 4的一個視圖中傳遞兩個模型列表?
projet name Myproject,
my model,
public class table1
{
public int id {get;set;}
public string student_name {get;set;}
}
public class table2
{
public int id {get;set;}
public string roll_number {get;set;}
}
my controller page,
list<table1> t=new list<table1>();
list<table2> t1=new list<table2>();
public ActionResult details()
{
sqlDataAdapter da=new sqldataAdapter("select * from Table1",con);
dataset ds=new dataset();
da.fill(ds);
foreach(datarow dr in ds.Table[0].row)
{
t.add(new table1()
{
id=int.parse(dr[0].ToString()),
student_name=dr[1].ToString()
}
}
sqlDataAdapter da1=new sqldataAdapter("select * from Table2",con);
dataset ds1=new dataset();
da1.fill(ds1);
foreach(datarow dr1 in ds1.Table[0].row)
{
t1.add(new table2()
{
id=int.parse(dr1[0].ToString()),
roll_number=dr1[1].ToString()
}
}
return details(t,t1);
}
view \\\\\\\\\\\\\\\\ My problem in view ,plase help me this problem.
@using MultiSelectList;
@model List<Myproject.Models.table1>
@model List<Myproject.Models.table2>
@{
ViewBag.Title = "Details";
}
<h1>Welcome to details page</h1>
[視圖中的多個型號(可能重複的http://計算器。 com/questions/4764011 /多模型在視圖) – DavidG 2014-12-02 11:52:42