小编Jep*_*fod的帖子

Web API - 返回复杂对象列表时出错

我创建了一个webAPI控制器方法,它看起来如下:

 [HttpGet]
 public HttpResponseMessage RealEstates()
 {
     using (BoligsideDbContext context = new BoligsideDbContext())
     {
         List<RealEstateVm> realEstateVms = context.RealEstates.OrderByDescending(x => x.Id).ToList().Select(x => new RealEstateVm(x)).ToList();

          return Request.CreateResponse(HttpStatusCode.OK, realEstateVms);
     }
}
Run Code Online (Sandbox Code Playgroud)

我的VM看起来如下:

public class RealEstateVm
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Description { get; set; }
        public int Area { get; set; }
        public int Rooms { get; set; }
        public int Rent { get; set; }
        public string Picture { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# serialization asp.net-web-api asp.net-web-api2

2
推荐指数
2
解决办法
4864
查看次数