【发布时间】:2016-08-24 15:08:39
【问题描述】:
namespace POS_Backend_.Controllers
{
public class hotelapiController : ApiController
{
private POSDBEntities db = new POSDBEntities();
// GET: api/hotelapi
public IList<HotelsDetailsDto> GetHotels()
{
return db.Hotels.Select(p => new HotelsDetailsDto
{ Id = p.Id,
Name = p.Name,
Address = p.Address,
Description = p.Description,
Offering = p.Offering,
Gps = p.Gps,
NumberOfRooms = p.NumberOfRooms,
Commission = p.Commission,
Rating = p.Rating,
HotelTypeName=p.HotelTypeName,
Image = p.Image,
LocationId = p.LocationId,
}).ToList();
}
我得到以下结果:
{
"Id": 2,
"Name": "Meilkles",
"Address": "samora machel avenue",
"Description": "luxury hotel",
"Offering": "swimming",
"Gps": "3672.22",
"NumberOfRooms": 5444,
"Commission": 65,
"HotelTypeName": "Lodge",
"Rating": 3,
"LocationId": 1,
"Image": "~/Banners/download(7).jpg",
"Comments": null,
"Favourites": null,
"Location": null,
"HotelType": null,
"Locations": null
}
【问题讨论】:
-
像这样返回 json { "Id": 2, "Name": "Meilkles", "Address": "samora machel avenue", "Description": "luxury hotel", "Offering": “游泳”,“Gps”:“3672.22”,“NumberOfRooms”:5444,“佣金”:65,“HotelTypeName”:“Lodge”,“评级”:3,“LocationId”:1,“图片”:“~ /Banners/download(7).jpg", "Comments": null, "Favorites": null, "Location": null, "HotelType": null, "Locations": null },
-
我编辑了您的问题以添加结果,这应该是编辑,而不是评论。如果您有更多信息,请编辑它。
标签: c# json entity-framework asp.net-web-api