This question has already been answered:

C server data goes and there is an id with a data type of ObjectId. On the client, it comes in this form:

Object { timestamp: 1476891401, machine: 13949887, p id: 10700, increment: 3401974, creationTime: "2016-10-19T15:36:41Z" } 

If you use .toString (), you get "[object Object]".

Action:

  public JsonResult GetPictures(int page = 0) { int count = 12; IMongoCollection<Photo> collection = DBConnection.GetInstance().GetCollection<Photo>("Photos"); List<Photo> pictures = collection.Find(new BsonDocument()).Skip(page * count).ToList().Take(count).ToList(); return Json(pictures); } 

Model Photo:

 public class Photo { public ObjectId Id { get; set; } public string Name { get; set; } public string Path { get; set; } public string[] Categories { get; set; } public DateTime DateTime { get; set; } } 

Reported as a duplicate at Grundy. javascript Jan 11 '17 at 11:39 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    I didn’t convert, decided the question like this:

     public JsonResult GetPictures(int page = 0) { int count = 12; IMongoCollection<Photo> collection = DBConnection.GetInstance().GetCollection<Photo>("Photos"); List<Photo> pictures = collection.Find(new BsonDocument()).Skip(page * count).ToList().Take(count).ToList(); var pics = pictures.Select(x => new { id = x.Id.ToString(), x.Name, x.Path, x.Categories, x.DateTime }).ToList(); return Json(pics); } 

    Added a line to action:

     var pics = pictures.Select(x => new { id = x.Id.ToString(), x.Name, x.Path, x.Categories, x.DateTime }).ToList();