服务器返回json

public JsonResult ListCompanyRepresentatives(int id)
{
    var party = _partyRepository.GetCompanyById(id);
    var names = from n in party.Representatives
                orderby n.ValidTo, n.RepresentativeParty.DisplayName
                select new 
                {
                    Id = n.Id.ToString(),
                    Name = n.RepresentativeParty.DisplayName,
                    Role = n.Role ?? string.Empty,
                    Context = n.Context ?? string.Empty,
                    ValidFrom = n.ValidFrom.ToShortDateString(),
                    ValidTo = n.ValidTo.ToShortDateString()
                };
 
    var rows = names.ToArray();
   
    var data = new 
    {
        total = rows.Count(),
        page = 1,
        records = rows.Count(),
        rows = rows
    };
 
    return Json(data, JsonRequestBehavior.AllowGet);       
}

posted on 2011-03-10 13:12  J-Pei  阅读(289)  评论(0编辑  收藏  举报

导航