I have an EntityFramework query in C # in an MVC, the problem is that the result of my code returns undefined, the code in C #:
public ActionResult ListarProductos()
{
sistemaEntities context = new sistemaEntities();
var lista = (from p in context.productos
select p).Where(p => p.nombre_producto.Contains(""));
return Json(new { success = true, message = lista }); // RETURN UNDEFINED
//return Json(new { success = true, message = "hola" }); // RETURN VALID OBJECT
}
The code in Ajax:
app.factory("AppService", function() {
return {
listProductos: function() {
var idata;
$.ajax({
type: 'POST',
url: "/CRUD/ListarProductos",
data: {},
dataType: 'json',
async: false,
success: function(result){idata = result;}
});
alert(idata);
return idata;
}, .. more code
The result in Ajax is "undefined" and I can not find a solution, the result in Ajax I then use it in AngularJS to display a table.
Not a duplicate, the second line of the code in c# works fine in ajax, the problem is the list in entity framework
The test line is commented out and returns a valid object
How can i fix this ?