I am returning an array of objects to a page that renders a slideshow based on a photo album.
I fetch my pictures from the database.
Before I return this array as a result, I would like to tack on a "Thumbnail" url property. This property does not exist on the AlbumPicture, but I want it in the response.
This illustrates the idea:
List<AlbumPicture> pics = db.AlbumPictures.Where(p => p.AlbumID == album.ID).OrderBy(p => p.RankOrder).ToList();
foreach(AlbumPicture p in pics)
{
p.AddPropertyThatDoesntExist("Thumbnail", ThumbManager.GetThumb(p.ID));
}
return Json(pics, JsonRequestBehavior.AllowGet);
What is the most elegant way to add this JSON field to my result set?
This question is so basic that it is probably a duplicate. However, I googled for 10 minutes and could only find janky solutions that depend on 3rd party libraries. I'm interested in the current "best practice".
Possible duplicate of: How to add dynamically more properties to Json response from the controller. However, that answer will make the dynamically added fields uncles instead of siblings to my AlbumPicture properties in the resulting JSON.