需要获取 Man 类的对象列表
public class Man
{
public int Id { get; set; }
public string Firstname { get; set; }
public string Secondname { get; set; }
public int Age { get; set; }
}
向服务器发送请求
$.ajax({
url: url,
type: "POST",
data: {
"count": count
},
dataType: "json"
})
在控制器方法中,我形成一个对象数组并将其发送给客户端
for (int i = 0; i < dif; i++)
{
mans[i] = await manContext.Mans.FirstOrDefaultAsync(m => m.Id == mansCount - dif + i);
}
return Json(mans);
如何使用 JS 从 JSON 中获取 Man 对象的字段值(姓名、年龄等)?
1 个回答