c# - ViewModel MVC 5 created using 2 classes, controller which using it -


it not new topic, after reading through many of them, i'm still not understand how can implement them in case. looking advise.

i have 2 classes.

public class media     {         public int id { get; set; }         public string title { get; set; }         public string description { get; set; }         public string body { get; set; }         public string imagepath { get; set; }     } 

and

public class video     {         public int id { get; set; }         public string title { get; set; }         public string description { get; set; }         public string videolink { get; set; }         public string tags { get; set; }     } 

at moment have 2 controllers each of them mediascontroller , videoscontroller, each of them works mediamain view , videomain view. in result can show 2 objects on 2 separate views. talking sort of media blog website, news may differ, may text only,text + image or text + video. every new "media" should populate on 1 view.

if talking on high level, think should create new viewmodel class gather fields need show on viewmodel page, right? here have:

public class mediaviewmodel     {         public class media          {                  public string title { get; set; }                 public string description { get; set; }                 public string body { get; set; }                 public string imagepath { get; set; }         }         public class video          {             public string title { get; set; }             public string description { get; set; }             public string videolink { get; set; }         } } 

now, if correct should have viewmodelcontroller made of class, right? or maybe need collection of both classes? mean this:

public class mediaviewmodel         {             public class media              {                      public string title { get; set; }                     public string description { get; set; }                     public string body { get; set; }                     public string imagepath { get; set; }                      **public video video{ get; set; }**             }     } 

please help.

you on right track, except class definition should this:

public class mediaviewmodel {    public media media { get; set; }    public video video { get; set; } } 

Comments