title: Bind data from database to DropDownListFor in asp.net mvc 2.0
body: <p>I am a new in asp.net mvc 2.0, I tried to search about this article but still can not get the answer like what I want.</p>
  
  <p>I have one form to assign the role to each employee. So I create one form that I can input the employee's name and select the role that they are in. The role are taking from table Role. I used linq to sql to query the RoleName and RoleID from table Role, and want to bind it to DropDownListFor in my view.</p>
  
  <p>I have one model :</p>
  
  <pre><code>public class UserModels
  {
  
     public string name { get; set; }
     public string role { get; set; }
  
  }
  </code></pre>
  
  <p>This is what I did in my controller :</p>
  
  <pre><code>[HttpPost]
  public ActionResult UserMaintenance(FormCollection frm)
  {
  if (ModelState.IsValid)
  {
      EMP_DBSEntities context = new EMP_DBSEntities();
      tblUserLogin user = new tblUserLogin();
      user.UserName = frm["userLogin"].ToString();
  
      IEnumerable&lt;SelectListItem&gt; role_list = context.tblRoles.Select(d =&gt; new SelectListItem
      {
          Value = d.RoleID.ToString(),
          Text = d.RoleName
      });
  
  
      context.AddTotblUserLogins(user);
      context.SaveChanges();
      return View();
  }
  else
  {
      return View();
  }
  }
  </code></pre>
  
  <p>Can anyone tell me how could I bind the <code>role_list</code> to my DropDownListFor&lt;> in my view.</p>
  
  <p>Thanks.</p>