title: Interaction between Models and ViewModels in ASP.NET MVC
body: <p>Could you explain the interaction Models and ViewModels in the ASP.NET MVC?</p>
  
  <ol>
  <li><p>If I need to display data on the page, but not edit, whether to create a ViewModel to display or use the Model?</p></li>
  <li><p>I have two methods in the repository. One returns the Model and the other Model gets.In View I need to send the model. Should I convert the resulting Model to a ViewModel that would pass it to the View, and upon receipt of the submission to convert it back into the model to keep it?</p></li>
  </ol>
  
  <p>For example I have a class model and class ViewModel.</p>
  
  <pre><code> public class Item
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public int Price { get; set; }
  }
  
  public class EditItemItemViewModel
  {
      public string Name { get; set; }
      public int Price { get; set; }
  }
  </code></pre>
  
  <p>On the edit page, I clicked the edit item, and must get to the controller:</p>
  
  <pre><code>    [HttpGet]
      public ActionResult EditItem(int id)
      {
         //some code
          return View();
      }
  </code></pre>
  
  <ol>
  <li><p>Where can I get the ID if I passed in the view ViewModel in which there was no ID?</p></li>
  <li><p>If I somehow got the ID, I need to do the following, which would save the model?</p>
  
  <pre><code>[HttpPost]
  public ActionResult EditItem(EditItemItemViewModel ViewModel)
  {
  
     var Item = _dataManager.Items.GetItemById("1");
     Item.Name = ViewModel.Name;
     Item.Price = ViewModel.Price;
  
     _dataManager.Items.AddItem(Item);
  
      return View("Sucsess");
  }
  </code></pre></li>
  </ol>
  
  <p>Could you tell me how to work with Models and ViewModels?</p>