1

I have two ListBoxs (multiple selection dropdownlist type) like follwing:

 @Html.ListBox("counTryIds", new SelectList(Model.CountryModels, "CountryId", "CountryName"), new { @class = "chosen-select", @id = "lbCountry", data_placeholder = "Select country...", style = "width: 100%" })
 @Html.ListBox("provinceIds", new SelectList(Model.ProvinceModels, "ProvinceId", "ProvinceName"), new { @class = "chosen-select", @id = "lbProvince", data_placeholder = "Select province...", style = "width: 100%" })

I would like to get list Province following some selected countries.

Example:

If I have 2 countries: VietNam, USA and 3 provinces: HaNoi, NewYork, HoChiMinh.

If I select VietNam => Dropdownlist Province will have HaNoi and HoChiMinh for selecting. As the same if I select USA -> have only NewYork. Beyond if select all countries VietNam, USA => show all provinces In controller I got 2 lists:

 reportLand.CountryModels = countries.ToList();
 reportLand.ProvinceModels = provinces.ToList();

The Country models:

 public string CountryId{ get; set; }

 [Required(ErrorMessage = CommonConstants.ErrorRequired)]
 public string CountryName { get; set; }

And Province model:

[Required(ErrorMessage = CommonConstants.ErrorRequired)]
public string ProvinceId { get; set; }

[Required(ErrorMessage = CommonConstants.ErrorRequired)]
public string ProvinceName{ get; set; }

public string CountryId { get; set; }
public string CountryName { get; set; }

As mentioned, I would like to get list Province following some selected countries. But I don't want to recall controller again to connect DB, only process in front end via jQuery or Js

Can everyone help me ? Thanks a lot.

1 Answers1

0

You need to use Jquery or ajax for get your solution.Just visit the following links it il help you

http://www.c-sharpcorner.com/UploadFile/4b0136/working-with-dropdownlist-in-mvc-5/

Fill drop down list on selection of another drop down list

Community
  • 1
  • 1
Vinoth
  • 851
  • 7
  • 23