title: ASP.NET MVC Page Validation Fails (The value is invalid.)
body: <p>I'm trying to create ASP.NET MVC Application with Entity Framework, which has One to Many relationship. For that I have successfully managed to load the appropriate list of items to a dropdown control (in Create view), But when I click the Create button (in Create view) page validation is faild, validation error message is <code>The value '1' is invalid.</code>.</p>
  
  <p><strong>Error</strong></p>
  
  <p><img src="https://i.stack.imgur.com/Wrwp0.jpg" alt=""></p>
  
  <p><strong>Model</strong></p>
  
  <pre><code>public class Post
  {
      public int Id { get; set; }
      ...
      public virtual Person Author { get; set; }
  }
  </code></pre>
  
  <p><strong>DataBaseContext</strong></p>
  
  <pre><code>protected override void OnModelCreating(DbModelBuilder modelBuilder)
  {
      modelBuilder.Conventions.Remove&lt;PluralizingTableNameConvention&gt;();
      modelBuilder.Entity&lt;Post&gt;()
                  .HasOptional(p =&gt; p.Author);
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>public ActionResult Create()
      {
          PopulateAuthorDropDownList();
          return View();
      }
  
      [HttpPost]
      public ActionResult Create(Post post)
      {
          if (ModelState.IsValid)
          {
              db.Posts.Add(post);
              db.SaveChanges();
              return RedirectToAction("Index");
          }
  
          PopulateAuthorDropDownList(post.Author);
          return View(post);
      }
  
      private void PopulateAuthorDropDownList(object selectedPerson = null)
      {
          var personQuery = from d in db.People
                            orderby d.Name
                            select d;
          ViewBag.Author = new SelectList(personQuery, "Id", "Name", selectedPerson);
      }
  </code></pre>
  
  <p><strong>View</strong></p>
  
  <pre><code>    &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Author)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.DropDownList("Author", String.Empty)
          @Html.ValidationMessageFor(model =&gt; model.Author)
      &lt;/div&gt;
  </code></pre>
  
  <p>When I check Author table in database there is Record with Id 1, so I guess 1 is a valid value. What am I missing here?</p>
  
  <p>Thanks in advance...</p>