Domanda

I have successfully created user control for address so that we can implant in student add view page, staff add view page.

And we can successfully taken the Actionresult of the page

 [HttpPost]
    public ActionResult Add(StudentModel StudentModel , AddressModel AddressModel)
    {

//code for executiom }

But I am stuck in the case when , for student we have to enter Communication address, parent office address etc.... . For that we have to call the address model Multiple times in the add view page of student by

       <%

           Html.RenderPartial("Addaddress", Model.CommunicationAddress);%>
         <%

      Html.RenderPartial("Addaddress", Model.ParentAddress);%>

Here How can we fill dropdown of country, then based on country -state then based on state -city.

When I tried, only dropdown of country is filling in both cases and for for communication address state is filling based on country. but its not happening for parent address.

1.How it can be done? 2. After that , in httppost , how can we retrieve both addresses?

Thanks in advance .

Please help.

È stato utile?

Soluzione

In MVC , user controls calling multiple times in same page have same control Ids. this is a Default Bug in MVC See this link

To over come this you have to add div with Id and in model add a divid and for each new instance assign new values for divid, then in populating Json, if you are using that you have to call that field for eg: $('#<%=Model.divid %> #CountryId').change, to get corresponding values .

For geting Model Values, only way i found is using Json to collect values from each div since, in actionresult finally you will get only one model.

I hope you got what you need.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top