0

我正在使用 MVC c# 我有一个对象

public class Person
{
        public int TypeId { get; set; }
        public string Code { get; set; }

}

我有一个代码可以像这样为这个对象重新运行 JSON 对象

return Json(personCodeStore.GetPersonCodes(id).Select(x=>new {text =x.Code, value =x.TypeId}), JsonRequestBehavior.AllowGet);

如何在我的 JSON 返回数据中添加一个指标,以便我可以检查空数据

$.getJSON('../PersonList?id=1', function (data) {
if (data==????)
{
alert("has data");
}
else
{
alert("is Empty");
}
}
4

1 回答 1

0

你能检查一下你知道 Person 对象会有的属性吗?像这样的东西:

if (data.Id) {
  // We got back something with an Id property... probably a Person
} else {
  // What else could we get back?!?
}
于 2013-01-13T04:51:47.853 回答