Receiving Multiple Objects from JQuery AJAX call

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-

  1. public JsonResult _GetTaskSearchResults(TaskSearchInput TaskSearchInput, bool loadFilterSetting)  
  2. {  
  3.    var result = new { objTaskSearchResult = objTaskSearchResult, DocumentTypeFilterCriteriaList = DocumentTypeFil   terCriteriaList, SettingDetails = SettingDetails };  
  4.   
  5.    return Json(result, JsonRequestBehavior.AllowGet);  
  6. }  
Client Side Changes-

For getting multiple objects at client side we can use below code-
  1. onSuccessloadTaskList: function (response) {  
  2.         var TaskSearchResult;  
  3.         var DocumentTypeFilterCriteriaList;  
  4.         var SettingDetails;  
  5.   
  6.         if (response != null) {  
  7.             if (response.objTaskSearchResult != null)  
  8.                 TaskSearchResult = response.objTaskSearchResult;  
  9.   
  10.             if (response.DocumentTypeFilterCriteriaList != null)  
  11.                 DocumentTypeFilterCriteriaList = response.DocumentTypeFilterCriteriaList;  
  12.   
  13.             if (response.SettingDetails != null)  
  14.                 SettingDetails = response.SettingDetails;  
  15.         }  
  16. }  

Ebook Download
View all
Learn
View all