[英]Asp.net how to Delete specific List Items from a Model
我有一個 model 包含一個列表,我需要根據MarkedForDeletion
值從 model 中刪除/刪除所有項目。
到目前為止,我已經嘗試了以下方法,但這無效,我寧願不使用 for 循環遍歷記錄。
public class CategoryModel
{
public string Label { get; set; }
public List<ItemModel> Items { get; set; }
}
public class ItemModel
{
public string Label { get; set; }
public bool MarkedForDeletion { get; set; )
}
CategoryModel.Items.Where(x => x.MarkedForDeletion = true).Remove;
您是否嘗試過RemoveAll()
將刪除與指定謂詞定義的條件匹配的所有元素?
CategoryModel.Items.RemoveAll(x => x.MarkedForDeletion);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.