为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 899 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信