<分区>
我需要清空 IEnumerable
列表我尝试了很多东西,比如 null 但都没有用
这是我的模型的样子
public class NewsViewModel
{
public NewsViewModel()
{
this.Categories = new List<Category>();
}
public int NewsId { get; set; }
public string NewsTitle { get; set; }
public string NewsBody { get; set; }
public IEnumerable<Category> Categories { get; set; }
}
if (!string.IsNullOrEmpty(SelectedCategoriesIds))
{
List<Category> stringList = new List<Category>();
stringList.AddRange(SelectedCategoriesIds.Split(',').Select(i => new Category() { CategoryId = int.Parse(i) }));
model.Categories = stringList.AsEnumerable();
}
else
{
model.Categories = null;
}
如何使 model.Categories
为空?