title: How to filter the options of a drop down list using another drop down list
body: <p>I am very new to ASP.NET and I am using the MVC 3 framework of ASP.Net. I was trying to filter the options of a dropdown list using another drop down and I can't manage to do that. I was trying to do this first by populating both the list of main categories and and sub categories and loading them to the page.Then setting the class attribute of the options of each sub-category to their parent category. Finally on the click of the parent category from the first dropdown list only show the child sub-category and hide the rest(This is how i did it previously in java). But in ASP.Net MVC the html code is so different i can't even set the class attribute for each option of the dropdown it generally sets the class for all the drop downs not for each option. This is what I have right now
  This is my View</p>
  
  <pre><code>&lt;p&gt;
  @Html.LabelFor(model =&gt; model.CategoryId)
  @Html.DropDownListFor(x =&gt; x.CategoryId , new SelectList(Model.Categories, "CategoryId", "CategoryName"), new { onchange= "this.form.submit();"})
  &lt;/p&gt;
  
  &lt;p&gt;
  @Html.LabelFor(model =&gt; model.SubCategories)
  @Html.DropDownListFor(x =&gt; x.SubCategories, new SelectList(Model.SubCategories, "SubCategoryId", "SubCategoryName"), new { @class = "Category1.categoryname" })
   &lt;/p&gt;
  </code></pre>
  
  <p>This is my model</p>
  
  <pre><code>public class TestQuestionsViewModel
  {
      public string CategoryId { get; set; }
      public IEnumerable&lt;Category&gt; Categories { get; set; }
  
      public string SubCategoryId { get; set; }
      public IEnumerable&lt;SubCategory&gt; SubCategories { get; set; }
   }
  </code></pre>
  
  <p>This is my controller class method</p>
  
  <pre><code>    public ActionResult Create()
      {
  
          var model = new TestQuestionsViewModel
          {
  
              Categories = resetDB.Categories.OrderBy(c =&gt; c.categoryid),
              SubCategories = resetDB.SubCategories.OrderBy(sc =&gt; sc.subcategoryid)
           };
       return View(model);
      }
  </code></pre>
  
  <p>My questions is How can i set the class attributes for each individual options. Or if anyone has a suggestion on how to do this in a different way I am open for any solution. Thank you.</p>