title: C# MVC2: How to get the selected value of a dropdownlist
body: <p>I am trying to convert a poorly developed C# web app to MVC2, and I am having difficulties trying to build a cascading dropdown. This is the code:</p>
  
  <pre><code>public IEnumerable&lt;SelectListItem&gt; SchoolList
      {
          get
          {
              DataTable dt = ClassModels.GetSchools();
              List&lt;SelectListItem&gt; list = new List&lt;SelectListItem&gt;();
              foreach (DataRow row in dt.Rows)
              {
                  list.Add(new SelectListItem
                  {
                      Text = Convert.ToString(row["School"]),
                      Value = Convert.ToString(row["SID"]),
                  });
              }
              return list;
          }
      }
  
      public IEnumerable&lt;SelectListItem&gt; DepartmentList
      {
          get
          {
              DataTable dt = DomData.GetDepartments(this is where the selected SID goes)
              List&lt;SelectListItem&gt; list = new List&lt;SelectListItem&gt;();
              foreach (DataRow row in dt.Rows)
              {
                  list.Add(new SelectListItem
                  {
                      Text = Convert.ToString(row["Department"]),
                      Value = Convert.ToString(row["DID"]),
                  });
              }
              return list;
          }
      }
  </code></pre>
  
  <p>This is the model for the Departments</p>
  
  <pre><code>public static DataTable GetDepartments(int id)
      {
          string sql = string.Format(@"SELECT d.department, d.did
              FROM dept d
              WHERE d.did IN (SELECT DISTINCT(DID) FROM CDS WHERE SID = '{0}')
              ORDER BY department", id);
  
          DataTable db_table = new DataTable("departments");
          SqlDataAdapter db_adapter = new SqlDataAdapter(sql, iau_conxn_string);
  
          db_adapter.Fill(db_table);
          //ddl_dep.DataSource = db_table;
          //ddl_dep.DataValueField = "did";
          //ddl_dep.DataTextField = "department";
          //ddl_dep.DataBind();
          return db_table;
      }
  </code></pre>
  
  <p>Sadly, I have to do this without AJAX or jQuery.</p>