title: Successful Model Editing without a bunch of hidden fields
body: <p><strong>In Short</strong>: How do I successfully edit a DB entry without needing to include every single field for the Model inside of the Edit View?</p>
  
  <p><strong>UPDATE</strong><br>
  So I have an item in the DB (an Article). I want to edit an article. The article I edit has many properties (Id, CreatedBy, DateCreated, Title, Body). Some of these properties never need to change (like Id, CreatedBy, DateCreated). So in my Edit View, I only want input fields for fields that can be changed (like Title, Body). When I implement an Edit View like this, Model Binding fails.  Any fields that I didn't supply an input for gets set to some 'default' value (like DateCreated gets set to 01/01/0001 12:00:00am). If I <em>do</em> supply inputs for every field, everything works fine and the article is edited as expected.  I don't know if it's correct in saying that "Model Binding fails" necessarily, so much as that "the system fills in fields with incorrect data if no Input field was supplied for them in the Edit View."</p>
  
  <p>How can I create an Edit View in such a way that I only need to supply input fields for fields that can/need editing, so that when the Edit method in the Controller is called, fields such as DateCreated are populated correctly, and not set to some default, incorrect value?  Here is my Edit method as it currently stands:  </p>
  
  <pre><code>    [HttpPost]
      public ActionResult Edit(Article article)
      {
          // Get a list of categories for dropdownlist
          ViewBag.Categories = GetDropDownList();
  
  
          if (article.CreatedBy == (string)CurrentSession.SamAccountName || (bool)CurrentSession.IsAdmin)
          {                
              if (ModelState.IsValid)
              {
                  article.LastUpdatedBy = MyHelpers.SessionBag.Current.SamAccountName;
                  article.LastUpdated = DateTime.Now;
                  article.Body = Sanitizer.GetSafeHtmlFragment(article.Body);
  
                  _db.Entry(article).State = EntityState.Modified;
                  _db.SaveChanges();
                  return RedirectToAction("Index", "Home");
              }
              return View(article);
          }
  
          // User not allowed to edit
          return RedirectToAction("Index", "Home");   
      }
  </code></pre>
  
  <p>And the Edit View if it helps:</p>
  
  <pre><code>. . .
  @using (Html.BeginForm()) {
  @Html.ValidationSummary(true)
  
  &lt;fieldset&gt;
      &lt;legend&gt;Article&lt;/legend&gt;
  
      &lt;p&gt;
          &lt;input type="submit" value="Save" /&gt; | @Html.ActionLink("Back to List", "Index")
      &lt;/p&gt;
  
      @Html.Action("Details", "Article", new { id = Model.Id })
  
      @Html.HiddenFor(model =&gt; model.CreatedBy)
      @Html.HiddenFor(model =&gt; model.DateCreated)
  
      &lt;div class="editor-field"&gt;
          &lt;span&gt;
              @Html.LabelFor(model =&gt; model.Type)
              @Html.DropDownListFor(model =&gt; model.Type, (SelectList)ViewBag.Categories)
              @Html.ValidationMessageFor(model =&gt; model.Type)
          &lt;/span&gt;
          &lt;span&gt;
              @Html.LabelFor(model =&gt; model.Active)
              @Html.CheckBoxFor(model =&gt; model.Active)
              @Html.ValidationMessageFor(model =&gt; model.Active)
          &lt;/span&gt;
          &lt;span&gt;
              @Html.LabelFor(model =&gt; model.Stickied)
              @Html.CheckBoxFor(model =&gt; model.Stickied)
              @Html.ValidationMessageFor(model =&gt; model.Stickied)
          &lt;/span&gt;            
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Title)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Title)
          @Html.ValidationMessageFor(model =&gt; model.Title)
      &lt;/div&gt;
      &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Body)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @* We set the id of the TextArea to 'CKeditor' for the CKeditor script to change the TextArea into a WYSIWYG editor. *@
          @Html.TextAreaFor(model =&gt; model.Body, new { id = "CKeditor", @class = "text-editor" })
          @Html.ValidationMessageFor(model =&gt; model.Body)
      &lt;/div&gt;
  &lt;/fieldset&gt;
  . . .
  </code></pre>
  
  <p>If I were to leave out these two inputs:</p>
  
  <pre><code>@Html.HiddenFor(model =&gt; model.CreatedBy)
  @Html.HiddenFor(model =&gt; model.DateCreated)
  </code></pre>
  
  <p>when the Edit method is called, they're set to default values. CreatedBy is set to <em>Null</em>, Created is set to <em>01/01/0001 12:00:00am</em></p>
  
  <p>Why are they not set to the values as they are currently set to in the DB?</p>