title: MVC ViewModel between Views best practice
body: <p>I need to build some Web screens with classic MVC architecture, containing Index page (list all instances of my class), Details (Check details of my class), Edit (Edit class data) and Delete (delete class instance).</p>
  
  <p>I´m using Viewmodel and Automapper. I´m in a doubt about the correct way to assing ViewModels and Automapper in that scenario, as the index will have a collection of class and each other view will have just one instance:</p>
  
  <p>Proposes Codes: </p>
  
  <p>OPTION1: ONE CLASS FOR EACH VIEW:</p>
  
  <pre><code>public class Person
  { 
       int id;
       string Name;
       int Age;
  }
  
  public class PersonViewModel
  {
       int id;
  
       [Display(name = "Person name")] 
       string Name;
  
       [Display(name = "Person age")] 
       int Age;
  }
  
  public class PersonIndexViewModel
  {
       List&lt;PersonViewModel&gt; Personlist;
  }
  
  
  PersonController:
  
  {
      var personList = db.List(); // Get data from db
  
      PersonIndexViewModel indexview = new PersonIndexViewModel();
  
      foreach (var item in personList)
      {  
           var tempview = new PersonViewModel();
           Map.Create (...); &lt;&lt; Here ? How ?
  
           indexview.PersonList.Add (tempview);
      }
  
      return view (indexview);
  }
  </code></pre>
  
  <p>OPTION2: ONE VIEWMODEL:</p>
  
  <pre><code>public class Person
  { 
       int id;
       string Name;
       int Age;
  }
  
  public class PersonViewModel
  {
       int id;
  
       [Display(name = "Person name")] 
       string Name;
  
       [Display(name = "Person age")] 
       int Age;
  }
  
  PersonController:
  
  {
      var personList = db.List(); // Get data from db
  
      List&lt;PersonViewModel&gt; viewList = new List&lt;PersonViewModel&gt;();
  
  
      foreach (var item in personList)
      {  
  
           var tempview = new PersonViewModel();
           Map.Create (...) // Here ? How ??
           viewList.Add (tempView);
       }
  
      return view (viewList);
  </code></pre>
  
  <p>}</p>
  
  <p>Is there something wrong if option 2? What would the best practices be on that case ?
  Thanks!</p>