Asp.net mvc 我应该为元素集合使用ViewModel:IList、IEnumerable还是列表类型?

Asp.net mvc 我应该为元素集合使用ViewModel:IList、IEnumerable还是列表类型?,asp.net-mvc,Asp.net Mvc,我应该在ViewModel中使用元素集合:IList、IEnumerable还是列表类型 这是我的ViewModel: public class NoteWithCommentsViewModel { public Notes Note { get; set; } public IList<Comments> Comments { get; set; } //Maybe it should be: List or IEnumerable? } 在视图中,我迭代注释-

我应该在ViewModel中使用元素集合:IList、IEnumerable还是列表类型

这是我的ViewModel:

public class NoteWithCommentsViewModel
{
    public Notes Note { get; set; }
    public IList<Comments> Comments { get; set; } //Maybe it should be: List or IEnumerable?
}

在视图中,我迭代注释-因此IEnumerable在ViewModel中应该足够,但在controller中,我必须使用ToList执行查询,所以我可能应该在ViewModel中使用List或IList?

可能的重复项,那么我应该在ViewModel中使用IList或IEnumerable吗?为什么必须在controller中使用.ToList?您应该使用最抽象的类型这让你可以做你需要做的一切。
var note = _notesService.GetNote(friendlyUrl);
var comments = _commentsService.GetNoteCommentsWithoutSpam(note.NoteId).ToList();

var noteWithCommentsViewModel = new NoteWithCommentsViewModel
{
    Note = note,
    Comments = comments
};