title: Best pratice for completing MVC model properties which aren't bound?
body: <p>I am trying to find the best way to use MVC for models which are only partially edited.</p>
  
  <p>Below is an simple example.</p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>using System.ComponentModel.DataAnnotations;
  public class SimpleModel
  {
      public int Id { get; set; }
      public string Parent { get; set; }
      [Required]
      public string Name { get; set; }
  }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>using System.ComponentModel.DataAnnotations;
  public class SimpleModel
  {
      public int Id { get; set; }
      public string Parent { get; set; }
      [Required]
      public string Name { get; set; }
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>using System.Web.Mvc;
  
  public class SimpleController : Controller
  {
      public ActionResult Edit(int id)
      { return View(Get(id)); }
  
      [HttpPost]
      public ActionResult Edit(int id, SimpleModel model)
      {
          if (model.Name.StartsWith("Child")) //Some test that is not done client-side.
          {
              Save(model);
              //Get the saved data freshly.
              //model = Get(id);
          }
          else
          {
              ModelState.AddModelError("", "Name should start with 'Child'");
          }
          //Is this the way to set the Parent property?
          //var savedModel = Get(id);
          //model.Parent = savedModel.Parent;
          return View(model);
      }
  
      //Mock a database.
      SimpleModel savedModel;
  
      private void Save(SimpleModel model)
      { savedModel = new SimpleModel() { Id = model.Id, Name = model.Name }; }
  
      private SimpleModel Get(int id)
      {
          if (savedModel == null)
          { return new SimpleModel() { Id = id, Parent = "Father", Name = "Child " + id.ToString() }; }
          else
          { return new SimpleModel() { Id = savedModel.Id, Parent = "Father", Name = savedModel.Name }; }
      }
  }
  </code></pre>
  
  <p>The Name field is editable. The Parent field is only for reference and should not be updated. Therefore, it is rendered using DisplayFor.</p>
  
  <p>Upon post, I receive a model with property Parent set to null. That's no problem as it will not be saved. However, when I simply return the received model to the view, the Parent field will no longer be displayed. When the model is valid, I can easily get it again from the database and thus get the Parent field's value back.</p>
  
  <p>When the model is not valid, I would like to allow the user to correct input and attempt to save once more. There, I the received model's values that are input should be used, but the displayed values should be shown as well.</p>
  
  <p>In reality, there are many more fields to be shown for reference, most often from different database entities than the one that is being edited.</p>
  
  <p>I have seen suggestions to pass the fields as hidden fields in the view, but I feel very reluctant to read data from the client that should not be updated.</p>
  
  <p>Is there a more elegant way to do this than copying these values into the model manually or passing them as hidden fields?</p>