Hi @jewel,
Modify your code like below:
Model
public class ordervm
{
public int orderId { get; set; }
public String orderNumber { get; set; }
public Decimal? Totalvalue { get; set; }
public List<tbl_order> tbl_order { get; set; } //add this property to store the extra data you want to display
//other properties
}
View
function format(d) {
var str = '';
$.each(d.tbl_order, function (index, data) {
str+= '<tr>' +
'<td>' + data.productID + '</td><td>' + data.oredrQty + '</td><td>' + data.salerate + '</td><td>' + data.value + '</td>'+
'</tr>'
});
console.log(str);
return '<table style="padding-left:50px;">' +
'<tr>' +
'<td>ProductID</td><td>oredrQty</td><td>salerate</td><td>value</td>' +
'</tr>' +
str+
'</table>';
}
Controller
public JsonResult Getrecord()
{
var List = from a in _context.tbl_Orders
group a by new { a.orderNumber } into g
select new ordervm
{
orderNumber = g.Key.orderNumber,
Totalvalue = g.Sum(x => x.value),
tbl_order = g.Select(t=>new tbl_order {
productID=t.productID,
oredrQty=t.oredrQty,
salerate=t.salerate,
value=t.value
}).ToList()
};
return Json(List);
}
Result
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena