title: Combo box asp.net mvc
body: <p>I have datatable in Index.cshtml scaffold-ed from Bus.cs</p>
  
  <pre><code>    public class Bus
      {
          public int BusID { get; set; }
  
          public int BusOwnerID { get; set; }
  
          public string RegistrationNo { get; set; }
      }
  </code></pre>
  
  <p>In the index page i need to include a dropdownlist with BusOwnerID and BusOwnerName from BusOwner.cs</p>
  
  <pre><code>    public class BusOwner
      {
          public int BusOwnerID { get; set; }
  
          public string BusOwnerName { get; set; }
  
          public string Moblie { get; set; }
  
          public string EmailID { get; set; }
      }
  </code></pre>
  
  <p>In the controller i have the following,</p>
  
  <pre><code>    public ActionResult Index()
      {
          ViewBag.Genres = db.BusOwners.Select(i =&gt; new SelectListItem { Value = i.BusOwnerID.ToString(), Text = i.BusOwnerName });
  
          return View(db.Buses.ToList());
      }
  </code></pre>
  
  <p>In the view, index.cshtml i need a dropdownbox with BusOwnerID and BusOwnerName. On selecting i need to display details of buses which comes under selected BusOwnerID.</p>
  
  <p>I tried the following</p>
  
  <pre><code>    @Html.DropDownListFor(model =&gt; model.BusOwnerID, new SelectList(ViewBag.Genres), "Choose... ")
  </code></pre>
  
  <p>But error occurs.</p>
  
  <pre><code>        CS1061: 'System.Collections.Generic.IEnumerable&lt;RaspberryPi.Models.Bus&gt;' does not contain a definition for 'BusOwnerID' and no extension method 'BusOwnerID' accepting a first argument of type 'System.Collections.Generic.IEnumerable&lt;RaspberryPi.Models.Bus&gt;' could be found (are you missing a using directive or an assembly reference?)
  </code></pre>
  
  <p>Index.cshtml</p>
  
  <pre><code>    @model IEnumerable&lt;RaspberryPi.Models.Bus&gt;
  
      @{
          ViewBag.Title = "Buses";
      }
  
      &lt;div class="btn-group"&gt;
          &lt;a href="/Buses/Create" class="btn btn-primary btn-lg"&gt;Create New&lt;/a&gt;
  
      &lt;/div&gt;
  
      @*@Html.LabelFor(model =&gt; model.BusOwnerID)
      @Html.DropDownListFor(model =&gt; model.SelectRegionId, Model.Regions, "Choose... ")
  
  
      @Html.DropDownList("drop", new SelectList(ViewBag.Genres));*@
  
      &lt;div id="Ttable" style="background:#f5f5f5;position:relative;width:100%;height:25%;"&gt;
          &lt;table id="example" class="display" cellspacing="0" width="100%"&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.RegistrationNo)&lt;/th&gt;
                      &lt;th&gt;@Html.DisplayNameFor(model =&gt; model.BusTypes)&lt;/th&gt;
                      &lt;th&gt;Edit&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  @foreach (var item in Model)
                  {
                      &lt;tr&gt;
                          &lt;td&gt;
                              @Html.DisplayNameFor(model =&gt; model.RegistrationNo)
                          &lt;/td&gt;
                          &lt;td&gt;
                              @Html.DisplayNameFor(model =&gt; model.BusTypes)
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;div class="btn-group"&gt;
                                  &lt;button type="button" class="btn-primary btn-xs" onclick="location.href = '/Buses/Details/@item.BusID';"&gt;&lt;span class="glyphicon glyphicon-th"&gt;&lt;/span&gt;&lt;/button&gt;
                                  &lt;button type="button" class="btn-success btn-xs" onclick="location.href = '/Buses/Edit/@item.BusID';"&gt;&lt;span class="glyphicon glyphicon-pencil"&gt;&lt;/span&gt;&lt;/button&gt;
                                  &lt;button type="button" class="btn-danger btn-xs" onclick="location.href = '/Buses/Delete/@item.BusID';"&gt;&lt;span class="glyphicon glyphicon-remove"&gt;&lt;/span&gt;&lt;/button&gt;
                              &lt;/div&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  }
              &lt;/tbody&gt;
          &lt;/table&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>How can i achieve that?</p>
  
  <p>Please help,
  Thanks.</p>