How to filter the options of a drop down list using another drop down list

前端 未结 2 1495
心在旅途
心在旅途 2020-12-08 03:20

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

2条回答
  •  情书的邮戳
    2020-12-08 04:04

    You need to add another method to handle the postback and filter the sub-category options. Something like this:

    [HttpPost]
    public ActionResult Create(TestQuestionsViewModel model)
    {
        model.SubCategories = resetDB.SubCategories
                .Where(sc => sc.categoryid == model.SubCategoryId)
                .OrderBy(sc => sc.subcategoryid);
        return View(model);    
    }
    

    Edit

    Btw, if you still need to set the class name to the other drop-down, you can't do it like that. The easiest way would by to add a "SelectedCategoryName" property to your model, and reference like { @class = ModelSelectedCategoryName }.

提交回复
热议问题