title: Asp.net MVC dropdownlist binding by using model classes
body: <p>I am writing MVC listing page which need to bundle with dropdownlist.<br>
  As I am very junior to ASP.net MVC, i don't know how to make dropdownlist to run correctly and make selected dynamically.</p>
  
  <p>I have two model classes</p>
  
  <pre><code>public class CycleType
  {
      public int CycleTypeID { get; set; }
      public string Type { get; set; }
  
      public List&lt;CycleModel&gt; CycleModels { get; set; }
  }
  
  -----------------------------------------------------------   
  
  public class CycleModel
  {
      public int CycleModelID { get; set; }
      public int CycleTypeID { get; set; }
      public string Model { get; set; }
  
      public virtual CycleType CycleType { get; set; }
  }
  </code></pre>
  
  <p>Then one Controller class,</p>
  
  <pre><code>public class CycleModelController : Controller
  {
  UnitOfWork&lt;CycleModel&gt; unitOfWork = new UnitOfWork&lt;CycleModel&gt;();
  UnitOfWork&lt;CycleType&gt; unitOfWork_cycleType = new UnitOfWork&lt;CycleType&gt;();
  
  ...
  
  [HttpGet]
  public ActionResult Edit(int CycleModelID)
  {
      CycleModel cycleModel = unitOfWork.GenericTEntityRepository.GetByID(CycleModelID);
      ViewBag.CycleType = new SelectList(unitOfWork_cycleType.GenericTEntityRepository.Get(orderBy: CycleTypes =&gt; CycleTypes.OrderBy(CycleType =&gt; CycleType.Type)));
      return View(cycleModel);
  }
  
  ...
  }
  </code></pre>
  
  <p>Then One Razor file,</p>
  
  <pre><code>&lt;div class="editor-field"&gt;
  @*Html.DropDownList("CycleType")*@
  @*Html.EditorFor(model =&gt; model.CycleTypeID)*@
  
  @Html.DropDownListFor(model =&gt; model.CycleTypeID,
                                  new SelectList(ViewBag.CycleType, "Type", "CycleTypeID"))
  @Html.ValidationMessageFor(model =&gt; model.CycleTypeID)
  &lt;/div&gt;
  </code></pre>
  
  <p>When I run my program, I get error message</p>
  
  <pre><code>DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'Type'.
  </code></pre>
  
  <p>1)How could I make correct this code ?<br>
  2)How could I make select item dynamically ?</p>
  
  <p>Every suggestion will be really appreciated.</p>
  
  <p> </p>