0
My problem is similar to that question: Question Stackoverflow
But in this case the object is used Json to popular 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 in this listing appeared the code of the product, but in fact I need to inform the description of this product and not the code.
You’re making the following mistake: A circular reference was detected when serializing an object of type 'Systemscommercial.Models.Itensvenda'.
Where is the product description?
– Leonel Sanches da Silva
In the table Product. I put
.Include(s => s.Produto)to do the JOIN.– user31040