title: How to bind a drop down with a model property while containing the list items of that drop down?
body: <p>I am stuck in a problem, I have retrieved all the value for a drop down in a view bag and want to display them at run time. I have achieved it by using the following code for the controller </p>
  
  <pre><code>    [HttpGet]
      public ActionResult Index()
      {
          var categoryList = new PersonalApp();
          SelectList catList = new SelectList(categoryList.GetAffinity().ToList(), "ClientName", "AffinityNum");
          ViewBag.categoryList = catList;
          return View();
      }
  </code></pre>
  
  <p>and the following code for the view</p>
  
  <pre><code>@using (Html.BeginForm("index", "Home"))
  {
  @Html.DropDownList("categoryList", "Branch Type")
  }
  </code></pre>
  
  <p>It really works but now I want to bind it with a model now. I have use the following code for this:</p>
  
  <pre><code> @Html.DropDownListFor(model=&gt;model.AffinityNum, "categoryList", "BranchType")
  </code></pre>
  
  <p>But it gives me an error as CategoryList cannot be used as a parameter with the above code. How will I get this resolved as I can have all the values of a dropdown in the categorylist and I can bind it with a model property affinityNum with it as well. </p>
  
  <p>Thanks </p>