i have 3 tables in database country ,state and district tables
initially am able to bind country list in my page,
if i click country i want show related states based on country id in another div same view page
like list (not in dropdownlist)
then if i click state i want to bind related districts based on state id
i have tried
public ActionResult Country()
{
//created view model to return multiple models to view
ViewModel vm = new ViewModel();
_countryAPI = new CountryAPI();
var country = _countryAPI.GetAll();
vm.countryViewModel = country .ToList();
return View(vm);
}
public JsonResult GetStates(int countryID)
{
ViewModel vm1 = new ViewModel();
_stateAPI = new StateAPI();
var states= _stateAPI .GetAll(countryID);
vm1.statesViewModel = states.ToList();
return Json(vm1, JsonRequestBehavior.AllowGet);
}
view
@using Sample.ViewModel
@model Sample.ViewModel
countries
@if (Model.countryViewModel != null)
{
foreach (var item in Model.countryViewModel)
{
}
}
else
{
}
States
@if (Model.statesViewModel != null)
{
foreach (var item1 in Model.statesViewModel)
{
}
}
else
{
no states
}
script
function stateClick(el) {
var countryID= $(el).attr("id");
$.ajax({
url: '/Home/GetStates',
type: "GET",
dataType: "json",
data: { countryID: countryID },
success: function (result) {
console.log(result);
},
error: function () {
console.log(error);
}
});
}
am able to bind list of countries and when i click country am getting country id and list but json result
not returning to view, json result returning view model and no result binding in view

Salman BegRank #284 · 8.8K reputationPosted Dec 8, 2016, 6:06 AM EST
Amit Kumar SinghRank #562 · 4.3K reputationPosted Dec 8, 2016, 4:52 PM EST