Hello everyone,
I am working on MVC 5, there I have Viewmodel Class ' PartnersVM '.
- public class PartnersVM
- {
- public List<CountryVM> listCountry { get; set; }
- public PartnerVM listPartnerVM { get; set; }
- }
-
- public class CountryVM
- {
- public int idCountry { get; set; }
- public string countries_name { get; set; }
- }
-
- public class PartnerVM
- {
- public string ServiceDistricts { get; set; }
- public string ServiceStates { get; set; }
- }
And this is ActionResult Get method.
- [HttpGet]
- public ActionResult PremiumUserRegistration()
- {
- PartnersVM objcountrymodel = new PartnersVM();
- objcountrymodel.listCountry = new List<CountryVM>();
- objcountrymodel.listCountry = objPartnerBIL.ShowCountries().Select(item => new CountryVM
- {
- idCountry = item.idCountry,
- countries_name = item.countries_name
- }).ToList();
- return View("PremiumUserRegistration", objcountrymodel);
- }
After calling this actionresult now binding list of countries. And the dropdown onchage calling a jscript function for bind below dropdowns also.
View:
- @Html.DropDownListFor(model => model.listCountry, new SelectList(Model.listCountry, "idCountry", "countries_name"), "Select", new { @class = "form-control ", @id = "ddlcountries", @onchange = "return getuserstate.search(this.value)" })
-
-
- @Html.DropDownListFor(model => model.listPartnerVM.ServiceStates, Enumerable.Empty<SelectListItem>(), "Select Country", new { @id = "ddlstate", @class = "form-control ", @onchange = "return getdistricts.search(this.value)" })
-
-
- @Html.DropDownListFor(model => model.listPartnerVM.ServiceDistricts, Enumerable.Empty<SelectListItem>(), "Select State", new { @id = "ddlDistrict", @class = "form-control " })
Now, all are working fine. But the problem is, I can not rebind those drowdown list while moving on edit page. Here Add/Edit page is one. How can I rebind the dropdownlist?
Please help me...