Build an empty MVC DropdownListFor for a Cascade Sub-List

前端 未结 3 552
滥情空心
滥情空心 2021-01-31 15:40

I would like to build an empty Dropdownlistfor to received the results of a previous Dropdownlisfor selection:

The actual view:

    
3条回答
  •  [愿得一人]
    2021-01-31 15:54

    Personally I would do this with a bit of jQuery and an additional partial view. Your form could look like this:

    @Html.DropDownListFor(m => m.Make_Id, Model.MakeList, HeelpResources.DropdownlistMakeFirstRecord)

    and then in your controller:

    public ActionResult GetModels(int id)
    {
       ViewBag.DdlModels = new SelectList(rep.GetModelsForCar(id), "Id", "Name");
       return PartialView();
    }
    

    and then just stick your drop down list in the GetModels partial view

提交回复
热议问题