Click here to Skip to main content
15,885,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi ,
i am new to MVC 4. i have an xml that contains country and state list. i need to read data from xml and display that in dropdown list. The condition is, first i need to read state from xml list and display that in state drop down. next based on that state selection, country dropdown have to change.


Example:

State: Nunavut

Country: Canada


Someone please help me.
Posted
Comments
Bala Selvanayagam 22-Aug-13 7:43am    
We can help you, if you have tried something out and stuck

I would suggest to get <nobr>visual studio installed and do a googling for a similar tutorial and try it out yourself first. If you are still stuck, we can help you out on this
Gayathri0191 22-Aug-13 8:20am    
yes i tried it in so many ways up-to my knowledge. but i dint get any value in country drop down.

this is my code:

in view:

<script type="text/javascript">

$(document).ready(function () {
$("#StateDropDown").change(function () {
debugger;
if ($('#StateDropDown').val() != "") {
$.ajax({
type: 'GET',
url: '@Url.Action("GetCountry",Url.RequestContext.RouteData.Values)' + '?stateId=' + this.value,
data: {},
success: function (result) {
$("#CountryDropDown").text(result);
alert(result);
},
error: function () { alert('Error'); }
});
}
});
});
</script>

@Html.DropDownListFor(m => m.State, (SelectList)ViewData["ddlstatename"], new { @class = "textEntryDropDown", id = "StateDropDown" })

@Html.DropDownListFor(m => m.Country, (SelectList)ViewData["ddlcountryname1"], new { @class = "textEntryDropDown", id = "CountryDropDown" })


in CONTROLLER:
[HttpGet]
public ActionResult GetCountry(string stateId)
{
string countryList = GetCountry1(stateId);
SelectList sl1 = new SelectList(countryList);
ViewData["ddlcountryname1"] = sl1;

return View();

// return Content(countryList);

}


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