c# - How to pass multiple model in view in ASP.NET MVC? -


problem is: want run 3 different actions instead of want fed data single action in bigger model.

i using:

public class searchscrapclass     {         public wclass wclass { get; set; }         public sclass sclass { get; set; }         public yclass yclass { get; set; }     }      public class wclass      {         public string title { get; set; }         public string link { get; set; }     }     public class sclass      {         public string title { get; set; }         public string link { get; set; }     }     public class yclass      {         public string title { get; set; }         public string link { get; set; }     } 

i using linq add data in these models.

i using :

      var wikians = info in document.documentnode.selectnodes("//div[@id='span']")         link in info.selectnodes("div//a").where(x => x.attributes.contains("href"))          select new searchscrapclass //main bigger class          {             wclass.link= link.attributes["href"].value, //error: how add wclass's url ?             wclass.title= link.innertext //error: how add wclass's url ?          }   var wikians = info in document.documentnode.selectnodes("//div[@id='results']")                link in info.selectnodes("p//a").where(x => x.attributes.contains("href"))                select new searchscrapclass //main bigger class                  {                    yclass.link= link.attributes["href"].value, //error: how add yclass's url ?                    yclass.title= link.innertext //error: how add yclass's url ?                  }  //also 3rd class (model)       return view(wikians); //and return bigger class model can access them in view 

this 1 way want add data link , title of classes.

my try add data 3 classes different sources , pass bigger model view can access classes as:

@model searchscrapclass @using(html.beginform()) {     @html.editorfor(o => o.wclass.link)     ... } 

please suggest way

thanks

to expand on comment, suggest creating viewmodel folder organization sake. in add view model

public class searchscrapclassviewmodel {     searchscrapclass searchscrap;     wclass wclass;     sclass sclass;     yclass yclass; } 

in controller instantiate new viewmodel

searchscrapclassviewmodel model = new searchscrapclassviewmodel {     ....add in logic fill class objects here   }  return view(model); 

then in view add using viewmodel.

@using searchscrapclassviewmodel 

Comments