title: Validation for Navigation Properties in MVC (4) and EF (4)
body: <p>I created a model with EF and then created a controller and view in MVC.
  The model type <code>A</code> has a Navigation Property to type <code>B</code>. So when I create <code>A</code> I want to select a <code>B</code>.</p>
  
  <p>The MVC wizard to create the controller and view only created fields for Scalar Properties. So I went and changed my create action on <code>A</code> to:</p>
  
  <pre><code>public ActionResult Create() //Create action for A
  {
      List&lt;B&gt; b = db.B.ToList(); //db is my DataContext
  
      ViewData["B"] = companies.Select(option =&gt; new SelectListItem
                      {
                          Text = (option.Name.ToString()),
                          Value = (option.Id.ToString())
                      });
      return View();
  }
  </code></pre>
  
  <p>And added to my view:</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.B)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.DropDownListFor(model =&gt; model.B,  (IEnumerable&lt;SelectListItem&gt;)ViewData["B"], "---- Select B ----")
      @Html.ValidationMessageFor(model =&gt; model.B)
  &lt;/div&gt;
  </code></pre>
  
  <p>All is good so far and I get the HTML</p>
  
  <pre><code>&lt;select class="valid" id="B" name="B"&gt;
      &lt;option value=""&gt;---- Select B ----&lt;/option&gt;
      &lt;option selected="selected" value="1"&gt;TestB&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>However when I submit I get the error:</p>
  
  <pre><code>The value '1' is invalid.
  </code></pre>
  
  <p>Having not written any validation it must have been auto-generated somewhere. How do I correct it to check the values against the ViewData["B"] collection ID's?</p>