Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; }  
    }  


What I have tried:

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 " })


Here getting those drowdown's value while going to edit Get action method as show below image.

[^]

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...
Posted
Updated 7-Mar-17 16:32pm
v2
Comments
Bryian Tan 7-Mar-17 21:49pm    
What do you mean by "moving on edit page. Here Add/Edit page is one"??
Member 12955507 7-Mar-17 21:52pm    
Means, there is have only one view page for Save and Update.
Karthik_Mahalingam 8-Mar-17 8:39am    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

 
Share this answer
 
Comments
Member 12955507 7-Mar-17 22:35pm    
sir, your answer for bind a DropDown on Selection Change of Another DropDown. I have already done that. Here I want rebind the drown while going to update with respect to Enumerable.Empty<selectlistitem>() . how can I solve this issue?
Graeme_Grant 7-Mar-17 23:20pm    
Please click on Improve question and explain what you mean by "Now, all are working fine. But the problem is, I can not rebind these DropDownList while moving on the edit page. Here Add/Edit page is one. How can I rebind the DropDownList?" & "...update with respect to Enumerable.Empty<selectlistitem>()" as both of these statements are unclear - thx.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900