我對使用ViewModels還是很陌生,我想知道,是否可以將ViewModel包含域模型的實例作為屬性,還是應(yīng)該將那些域模型的屬性作為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 回答
- 0 關(guān)注
- 1122 瀏覽
添加回答
舉報
0/150
提交
取消