title: asp.net mvc - Populate a dropdownlist from a seperate model/Database Table
body: <p>Let's say I have two tables. <strong>Inventory</strong> and <strong>Supplier</strong>. Inventory has three fields : <strong>name</strong>, <strong>inventory_no</strong> and <strong>supplier_no</strong> and Supplier has two fields : <strong>name</strong>, <strong>supplier_no</strong></p>
  
  <p>In my View for Inventory is it possible to add a cell with a <code>@Html.DropDownListFor()</code> populated from a separate <strong>supplies</strong> model?</p>
  
  <p>I can't figure out how to accomplish it using the Controller/View so I was thinking about using AJAX</p>
  
  <p>Example:</p>
  
  <pre class="lang-none prettyprint-override"><code>Name    | Inv_no | Suppliers
  ------- | ------ | ------------------------------
  Pen     | 101    | DDL populated of all suppliers
  Pencil  | 102    | DDL populated of all suppliers
  Erase   | 103    | DDL populated of all suppliers
  </code></pre>
  
  <p>VIEW:</p>
  
  <p></p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;Inventory_No&lt;/th&gt;
          &lt;th&gt;Suppliers&lt;/th&gt;
      &lt;tr&gt;
          @foreach(var item in Model)
          {
              &lt;td&gt;@Html.DisplayFor(modemItem =&gt; item.name)&lt;/td&gt;
              &lt;td&gt;@Html.DisplayFor(modemItem =&gt; item.inventory_no)&lt;/td&gt;
              &lt;td&gt;&lt;!-- @Html.DropDownListFor() ? --&gt;&lt;/td&gt;
          }
  &lt;/table&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <p></p>
  
  <pre><code>public virtual JsonResult  getListOfSuppliers(int? supplier_no)
  {
      using (db)
      {
          var vendors = db.vendors.Select(c =&gt; new
          {
              Value = c.supplier_no,
              Text = c.name
          });
          return Json(vendors, JsonRequestBehavior.AllowGet);
      }
  }
  </code></pre>