1 回答

TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超5個(gè)贊
以下解決方案將提供您正在尋找的內(nèi)容。真正的關(guān)鍵是創(chuàng)建一個(gè)中間對(duì)象來保存您要查找的條目,而不是簡(jiǎn)單地將文件放在字典中。另一個(gè)復(fù)雜因素是您實(shí)際上是在尋找字典列表,其中每個(gè)字典都包含一個(gè)文件名/已刪除的條目。
文件收集類:
public class FileCollection
{
[JsonProperty("files")]
public List<Dictionary<string, bool>> Files { get; set; }
public FileCollection()
{
Files = new List<Dictionary<string, bool>>();
}
}
您現(xiàn)有的邏輯,修改為使用新的集合類:
public async Task<JsonResult> DeleteImages(List<string> ids)
{
var files = new FileCollection();
foreach (var id in ids)
{
var file = await _fileService.GetByIdAsync(id);
if (await AzureStorage.DeleteFile(file))
{
files.Files.Add(new Dictionary<string, bool> { { file.Name, true } });
}
}
return Json(JsonConvert.SerializeObject(files));
}
- 1 回答
- 0 關(guān)注
- 371 瀏覽
添加回答
舉報(bào)