Introduction
As per requirement in our project I was looking for this solution how to receive multiple objects from JQuery in Ajax call. I searched on google but there was not proper solution so I want to share this small but imp thing with team.
Controller Method Changes
Create new 'result' object of var datatype. Assign all objects to 'result' object as below-
- public JsonResult _GetTaskSearchResults(TaskSearchInput TaskSearchInput, bool loadFilterSetting)
- {
- var result = new { objTaskSearchResult = objTaskSearchResult, DocumentTypeFilterCriteriaList = DocumentTypeFil terCriteriaList, SettingDetails = SettingDetails };
-
- return Json(result, JsonRequestBehavior.AllowGet);
- }
Client Side Changes-
For getting multiple objects at client side we can use below code-
- onSuccessloadTaskList: function (response) {
- var TaskSearchResult;
- var DocumentTypeFilterCriteriaList;
- var SettingDetails;
-
- if (response != null) {
- if (response.objTaskSearchResult != null)
- TaskSearchResult = response.objTaskSearchResult;
-
- if (response.DocumentTypeFilterCriteriaList != null)
- DocumentTypeFilterCriteriaList = response.DocumentTypeFilterCriteriaList;
-
- if (response.SettingDetails != null)
- SettingDetails = response.SettingDetails;
- }
- }