0
這是我在stackoverflow上的第一個問題,所以如果標題或問題不好,請原諒。Kentico圖像API - 需要在ASP.NET Web API中返回圖像URL而不是Guid
在我VoucherResponse類
public class VoucherResponse
{
public int VoucherID { get; set; }
public string VoucherTitle { get; set; }
public IEnumerable<VoucherVariant> VoucherVariants { get; set; }
public string[] VoucherImages { get; set; }
}
和Web API方法
return Ok(from v in distinctby
select new VoucherResponse
{
VoucherID = v.VoucherID,
VoucherTitle = v.VoucherTitle,
VoucherVariants = (from voucher in voucherToLookup[v.VoucherID]
select new VoucherVariant
{
VoucherDiscountedPrice = voucher.VoucherPrice - (voucher.VoucherPrice * voucher.VoucherDiscount/ 100),
VoucherVariantId = voucher.VoucherVariantId,
VoucherPrice = voucher.VoucherPrice,
VoucherStock = 1
}),
VoucherImages = (from image in distinctby
where v.VoucherID == image.VoucherID
select image.VoucherImages
// URLHelper.GetAbsoluteUrl(ModuleCommands.MediaLibraryGetMediaFileUrl(image.FileGUID, voucher.NodeAlias + "_" + image.ImageOrder))).ToArray(),
).ToArray()
});
目前我得到的結果的那一刻
{
"voucherID": 380,
"voucherTitle": "Woolworths e-Gift Card",
"voucherVariants": [
{
"voucherVariantId": 397,
"voucherPrice": 100,
"voucherDiscountedPrice": 95,
"voucherStock": 1
},
{
"voucherVariantId": 389,
"voucherPrice": 200,
"voucherDiscountedPrice": 190,
"voucherStock": 1
},
{
"voucherVariantId": 393,
"voucherPrice": 300,
"voucherDiscountedPrice": 285,
"voucherStock": 1
},
{
"voucherVariantId": 394,
"voucherPrice": 400,
"voucherDiscountedPrice": 380,
"voucherStock": 1
},
{
"voucherVariantId": 395,
"voucherPrice": 500,
"voucherDiscountedPrice": 475,
"voucherStock": 1
}
],
"voucherImages": [
" B4A3A070-3ED1-4086-8B33-21465AA58C7A, 2FB01963-2D71-4C79-9EE8-38A114CAF1A6"
]
我需要回到這樣voucherImages
"VoucherImages" : [
{"www.kentico.info/imageOne.jpg"}
{"www.kentico.info/imageTwo.jpg"}
]
問題是什麼?你爲什麼不這樣格式化數據並返回? – JotaBe
問題出在標題和最後一段。不知道如何使它工作 –
你在哪裏存儲圖像? (媒體庫/附件/文件頁面類型...?)或者您使用哪種表單控件來存儲圖像? – rocky