asp.net mvc 4 - How to pass two model list in one view in mvc 4? -


my problem list<>,i taking 2 model in 2 list in controller action method pass values in 2 lists can not pass 2 list values in view,i giving code below,please give solution this.

    projet name myproject,      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;}     }      controller page,      list<table1> t=new list<table1>();     list<table2> t1=new list<table2>();     public actionresult details()     {        sqldataadapter da=new sqldataadapter("select * 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 * 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   \\\\\\\\\\\\\\\\ problem in view ,plase me problem.      @using multiselectlist;     @model  list<myproject.models.table1>     @model  list<myproject.models.table2>       @{         viewbag.title = "details";     }      <h1>welcome details page</h1> 

it's easy. create class includes 2 lists.

public class custommodel     {         public list<table1> table1 { get; set; }          public list<table2> table2 { get; set; }     } 

and in controller return custommodel

return details(t,new custommodel { table1 = t1, table2 = t2 }); 

and in view

@model  myproject.models.custommodel 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -