I am using a method to return an object of type JSON but it is not listing the information:
My Controller
public ActionResult GetDados()
{
int codigoVenda = 2;
try
{
SistemaDBEntities db = new SistemaDBEntities();
List<ItensVenda> itensVenda = new List<ItensVenda>();
itensVenda = db.ItensVenda.Where(s => s.CodigoVenda == codigoVenda).ToList();
//var venda = db.Venda.Where(s => s.Codigo == codigoVenda).ToList();
return Json(itensVenda, JsonRequestBehavior.AllowGet);
}
catch (Exception)
{
throw;
}
}
My Script
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Venda/GetDados",
success: function (itensVenda) {
if (dados != null) {
$('#tbody').children().remove();
$(itensVenda).each(function (i) {
var tbody = $('#tbody');
var tr = "<tr>";
tr += "<td>" + itensVenda[i].CodigoProduto;
tr += "<td>" + itensVenda[i].Quantidade;
tr += "<td>" + itensVenda[i].PrecoUnitario;
tr += "<td>" + "<button class='btn btn-info' onclick=Editar(" + itensVenda[i].Id + ")>" + "Editar";
tr += "<td>" + "<button class='btn btn-danger' onclick=Deletar(" + itensVenda[i].Id + ")>" + "Deletar";
tbody.append(tr);
});
}
}
});
});
I'm pretty sure he does not list because of this error:
Does anyone know what's wrong?