asp.net mvc - How to strongly type a view with 2 classes? -


is possible type view 2 tables? mean if want display view contains data coming 2 tables , how stongly type view data comes 2 tables?

you can't directly can create viewmodel class 2 properties on hold references table. type view against viewmodel class.

viewmodel:

public class viewmodeltables {    public mytable customer {get; set;}    public myothertable myothertable {get; set;} } 

view:

<%@ control language="c#" inherits="system.web.mvc.viewusercontrol<viewmodeltables>" %>  <% foreach(var tab1item in model.customer)    { %>    // render here ever want render    <%: html.textboxfor(name => tab1item.name) %> <% } %>  <% foreach(var tab2item in model.myothertable)    { %>    // render here ever want render <% } %> 

controller:

public actionresult mydoubletables() {    var my2tab = new viewmodeltables();     var tab1 = gettable1(); // whatever need     var tab2 = gettable2(); // whatever need      my2tab.mytable = tab1;    my2tab.myothertable = tab2;     return view(my2tab); } 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -