My problem is similar to this question: Question Stackoverflow
But in this case the Json object is used to populate the table.
Controller
public ActionResult GetDadosItensVenda(int? Codigo)
{
try
{
db.Configuration.ProxyCreationEnabled = false;
db.Configuration.LazyLoadingEnabled = false;
List<ItensVenda> itensVenda = new List<ItensVenda>();
itensVenda = db.ItensVenda.Include(s => s.Produto).Where(s => s.CodigoVenda == Codigo && s.Ativo == true).ToList();
return Json(itensVenda, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
throw;
}
}
Script
<script>
$(document).ready(function () {
var CodigoVenda = @ViewBag.CodigoVenda;
$.ajax({
type: "GET",
url: "/Venda/GetDadosItensVenda?Codigo="+ CodigoVenda,
success: function (itensVenda) {
if (itensVenda != null) {
var total = 0;
$('#tbody').children().remove();
$(itensVenda).each(function (i) {
total += (itensVenda[i].PrecoUnitario * itensVenda[i].Quantidade);
var tbody = $('#tbody');
var tr = "<tr>";
tr +=
tr += "<td>" + itensVenda[i].Codigo;
tr += "<td>" + itensVenda[i].CodigoProduto;
tr += "<td>" + itensVenda[i].Quantidade;
tr += "<td>" + itensVenda[i].PrecoUnitario;
tr += "<td>" + (itensVenda[i].PrecoUnitario * itensVenda[i].Quantidade);
tbody.append(tr);
});
}
$("#Total").html("<p>"+ total + "</p>");
}
});
});
This listing worked normally, but the listing listed the product code, but in fact you need to enter the description for that product, not the code.
You are giving the following error: A circular reference was detected when serializing an object of type 'CommercialSystem.Models.ItemsSale'.