Answer the question
In order to leave comments, you need to log in
Using return Json() method on client in success function(data) undefined. How to fix?
Project on asp.net core, web api 2.
Method:
There are approximately 600 products in the database. Linq selection pulls out goods, checked it in the debugger.
[HttpPost("ConfectionsJsonResult")]
public JsonResult ConfectionsJsonResult()
{
IEnumerable<Products> confections = DbNorthWind.Products.Where(p => p.CategoryId == 3);
return Json(confections);
}
$.getJSON({
type: 'POST',
dataType: 'json',
contentType: 'application/JSON',
url: '/api/Product/ConfectionsJsonResult',
success: function (data) {
var results = $("#ConfectionsList");
alert(data); //[object Object],[object Object],[object Object],[object Object],[object Object],...
alert(data[0].ProductName); //undefined
[HttpPost("ConfectionsJsonResult")]
public JsonResult ConfectionsJsonResult()
{
var confections = DbNorthWind.Products.Where(p => p.CategoryId == 3);
var JsonConfections = JsonConvert.SerializeObject(confections);
return Json(JsonConfections );
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question