I have two controller
Settings Controller
Action - GetAvailableLocationsFor
HomeController
Action - Index
Steps I want to acheive
- Make ajax call to
GetAvailableLocationsForand then get the object data from success call back. No view is required for this Action. - Now with the object data received make another ajax call to Index Action in HOMECONTROLLER and pass the object there.
Below is what I could achieve.
HomeController - GetAvailableLocationsFor
public ActionResult GetAvailableLocationsFor(int accountId, int groupId)
{
FullConfigMV configData = SetLoader.GetSettings(accountId, groupId);
return // HOW TO RETURN configData from Here to first ajax call
}
HomeController - Index Action
[HttpPost]
public ActionResult Index(FullConfigMV data)
{
//SECOND AJAX CALL SHOULD COME HERE
}
Nested Ajax call
<script>
$(document).ready(function()
{
$("#tan").change(function()
{
alert(this.value);
$.ajax({
type: 'POST',
url: '/Settings/GetAvailableLocationsFor',
data: { accountId: 28462, groupId: 35},
success: function (data) { // data should represent configObj
$.ajax({
type: 'POST',
url: '/Home/Index',
data: // WHAT TO WRITE HERE,
success: function (data) {
//WHATEVER
},
error: function () {
DisplayError('Failed to load the data.');
}
});
},
error: function () {
DisplayError('Failed to load the data.');
}
});
});
});
</script>
return Json(configData, JsonRequestBehavior.AllowGet);anddata: data(but this could simply be done using one ajax call to one method - its not clear why you want 2 methods)GetAvailableLocationsForand the Index sometimes needs to be called independent of the logic which is inGetAvailableLocationsForGetAvailableLocationsForto be called and then the index should be called.