I am trying to return list of list as json from my controller,
my controller code:
using Newtonsoft.Json;
[HttpGet]
public JsonResult GetPpi()
{
var customer = EngineContext.Current.Resolve<IWorkContext>().CurrentCustomer;
var psg = _xDetailService.GetXDetailbyCustomerId(customer.Id);
var model2 = new List<List<XDetail>>();
foreach (var pr in psg)
{
var plan = _xDetailService.GetXDetailbyId(pr.Id);
var model = new List<XDetail>();
foreach (var x in plan)
{
model.Add(new XDetail
{
Id = x.Id,
XNo = x.XNo,
XName = x.XName,
XSurname = x.XSurname
});
}
model2.Add(model);
}
return Json(model2, JsonRequestBehavior.AllowGet);
}
and my ajax call:
function GetPlans() {
$.ajax({
cache: false,
type: "GET",
url: "/XDetail/GetPpi",
data: {},
dataType: 'json',
});
}
XDetail:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Nop.Core.Domain.UnExpected
{
public partial class XDetail: BaseEntity
{
public int? XNo { get; set; }
public string XName { get; set; }
public string XSurname { get; set; }
public double? XDec { get; set; }
public int? XMaster_Id { get; set; }
public virtual XMaster XMaster { get; set; }
}
}
When I put a break point at return model2 contains all the values I needed in List of List. But if I continue they return as null.
I am missing something but couldn't find what...
and also using AspNet Mvc 5