亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

MVC / MVVM /分層中的ViewModels-最佳做法?

MVC / MVVM /分層中的ViewModels-最佳做法?

慕標5832272 2019-12-04 10:50:44
我對使用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 關注
  • 1131 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號