zeeshan akram

zeeshan akram

  • 1.3k
  • 325
  • 16.6k

How to return two object using json and receive using jquery

Mar 3 2020 6:39 AM
 Hi, these are two objects and I want to access these two objects on view using jquery. I have tried a lot of but I could receive these two objects. when I remove one object data will be received successfully but two objects at a time I could not access.  
any expert can you tell me combine two objects and received in view using jquery. 
  1. ECommercedbEntities db = new ECommercedbEntities();  
  2.             var productl = (from p in db.Products  
  3.                             where p.ProductID == id  
  4.                             select new  
  5.                             {  
  6.                                 PName = p.PName.Trim()
  7.                             }).FirstOrDefault();  
  8.   
  9.             var productD = (from pd in db.ProductDetails  
  10.                             join p in db.Products on pd.ProductID equals p.ProductID  
  11.                             where pd.ProductID == id  
  12.                             select new  
  13.                             {  
  14.                                 ProductID = pd.ProductID,  
  15.                                 OS = pd.OS,  
  16.                             }).ToList();  
  17.   
  18.             return Json(,JsonRequestBehavior.AllowGet);  // i have try this return Json(new{productl, productD },JsonRequestBehavior.AllowGet) // but i could not receive in jquery 
 jquery access
  1. function GetProductByID(ID)  
  2.   {  
  3.       $.ajax({  
  4.           url: "/Items/GetProd/" + ID,  
  5.           typr: "GET",  
  6.           contentType: "application/json;charset=UTF-8",  
  7.           dataType: "json",  
  8.             
  9.           success: function (res) {  
  10.         
  11.               $('#PName').val(res.Model);  
  12.               $('#mProduct').modal('show');  
  13.               $('#btnUpdate').show();  
  14.               $('#btnSave').hide();  
  15.           },  
  16.           error: function (errormessage) {  
  17.               alert(errormessage.responseText);  
  18.           }  
  19.       });  
  20.       return false;  
  21.   }  

Answers (4)