title: MVC 3 Model Binding without Key
body: <p>I have a question about ASP.NET MVC3 model binding. If I have a class I'm trying to use as a model, but I don't want the key put on the page, the model doesn't bind on a POST. Here is an example:</p>
  
  <pre><code>//Data Model
  public class MyModel
  {
      [Key]
      public string MyKey {get;set;} //Perhaps this is an ssn that I don't want on the form.
      public string MyValueToGet {get;set;} //This is the value I want the user to enter.
  }
  
  //Conroller code.
  public ViewResult Index()
  {
      MyModel model = new MyModel{ MyKey = "SecretInfo", MyValueToGet = "" };
      return View(new model);
  }
  public ActionResult Edit(MyModel model)
  {
      repository.SaveChanges(model)
  }
  
  //View code.
  @using(Html.BeginForm("Edit", "Home", FormMethod.Post))
  {
      Enter a value: @Html.EditorFor(m =&gt; m.MyValueToGet)
      &lt;input type="submit" value="Salve" /&gt;
  }
  </code></pre>
  
  <p>So my problem is that model is null when the Edit method is called upon form submission. I can fix this by putting MyKey somewhere on the page (perhaps as a hidden field), but that is unacceptable if it is some sort of sensitive data. Is there a way to solve this problem? I am new to MVC, so I appreciate any help.</p>