2
I’m wearing a method to return an object of the type JSON but is not listing the information:
Man 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;
}
}
Man 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 doesn’t list because of that mistake:
Someone knows what’s wrong?
I believe that this is not the best approach to what search, I would use partialView to fill the table. But, try to access the url localhost:63729/sale/Getdados and post the error that is appearing
– Randrade
This error appears: A circular reference was detected when serializing an object of type 'System.Data.Entity.DynamicProxies.Venda_9f946f25ade24f28cdca309e65a9e7ece50af4c1b01232ed376a7b4dcf436e82'.
– user31040
Take a look in this answer, that you can solve your problem. And edit your question and add the error in it, it is easier to understand your real problem.
– Randrade
Actually there is a bit of difference one is Webforms the other is Aspnet MVC and besides
db.Configuration.ProxyCreationEnabled = false;
(Entityframework configuration, which is recommended to take) avoids giving the error and solves the problem without having to make another class and configuration. Of course the proposed response is also a solution, but at another time in another case I believe it would be legal to have the solutions for both! I don’t think DUPLICATE!– Cezar