Abhilash J A

Abhilash J A

  • 501
  • 2.4k
  • 598.1k

How can I rebind the drowdownlist in Edit page MVC

Mar 7 2017 9:58 AM
Hello everyone,
 
 I am working on MVC 5, there I have Viewmodel Class ' PartnersVM '.
  1. public class PartnersVM  
  2.    {  
  3.        public List<CountryVM> listCountry { getset; }  
  4.        public PartnerVM listPartnerVM { getset; }  
  5.    }   
  6.   
  7. public class CountryVM  
  8.    {  
  9.        public int idCountry { getset; }  
  10.        public string countries_name { getset; } 
  11.    }  
  12.   
  13. public class PartnerVM  
  14.    {  
  15.      public string ServiceDistricts { getset; }  
  16.      public string ServiceStates { getset; }  
  17.     } 
And this is ActionResult Get method.
  1. [HttpGet]  
  2. public ActionResult PremiumUserRegistration()  
  3.        {  
  4.          PartnersVM objcountrymodel = new PartnersVM();  
  5.           objcountrymodel.listCountry = new List<CountryVM>();  
  6.                        objcountrymodel.listCountry = objPartnerBIL.ShowCountries().Select(item => new CountryVM  
  7.                        {  
  8.                            idCountry = item.idCountry,  
  9.                            countries_name = item.countries_name  
  10.                        }).ToList();  
  11. return View("PremiumUserRegistration", objcountrymodel);                      
  12.         } 
 After calling this actionresult now binding list of countries. And the dropdown onchage calling a jscript function for bind below dropdowns also.
 
View:
  1. @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)" })  
  2.   
  3.   
  4. @Html.DropDownListFor(model => model.listPartnerVM.ServiceStates, Enumerable.Empty<SelectListItem>(), "Select Country", new { @id = "ddlstate", @class = "form-control ", @onchange = "return getdistricts.search(this.value)" })  
  5.   
  6.   
  7. @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...
 

Answers (5)