title: How to realize DropDownListFor in View?
body: <p>I want to show all names of "Category" in the dropdownlist in Create View by HtmlHelper. </p>
  
  <p>The Model of "Category" is:</p>
  
  <pre><code>public class Category
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string Description { get; set; }
  }
  </code></pre>
  
  <p>The Controller is:</p>
  
  <pre><code>public ActionResult Create()//
  {
      ViewBag.Categorys = new SelectList(categoryRepo.SelectAll(), "Id", "Name");
      return View();
  }
  </code></pre>
  
  <p>The View is:</p>
  
  <pre><code>&lt;div class="form-group"&gt;
      @Html.LabelFor(model =&gt; model.CategoryId, htmlAttributes: new { @class = "control-label col-md-2" })
      &lt;div class="col-md-10"&gt;
          @Html.DropDownListFor(model =&gt; model.CategoryId, (SelectList)ViewBag.Categorys, new { htmlAttributes = new { @class = "form-control" } })
          @Html.ValidationMessageFor(model =&gt; model.CategoryId, "", new { @class = "text-danger" })
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>