我对使用ViewModels还是很陌生,我想知道,是否可以将ViewModel包含域模型的实例作为属性,还是应该将那些域模型的属性作为ViewModel本身的属性?例如,如果我有一堂课Album.cspublic class Album{ public int AlbumId { get; set; } public string Title { get; set; } public string Price { get; set; } public virtual Genre Genre { get; set; } public virtual Artist Artist { get; set; }}通常是让ViewModel持有Album.cs该类的实例,还是让ViewModel拥有Album.cs该类的每个属性的属性。public class AlbumViewModel{ public Album Album { get; set; } public IEnumerable<SelectListItem> Genres { get; set; } public IEnumerable<SelectListItem> Artists { get; set; } public int Rating { get; set; } // other properties specific to the View}public class AlbumViewModel{ public int AlbumId { get; set; } public string Title { get; set; } public string Price { get; set; } public IEnumerable<SelectListItem> Genres { get; set; } public IEnumerable<SelectListItem> Artists { get; set; } public int Rating { get; set; } // other properties specific to the View}
2 回答
- 2 回答
- 0 关注
- 1071 浏览
添加回答
举报
0/150
提交
取消