ASP.NET MVC ViewModel Pattern

后端 未结 4 1225
广开言路
广开言路 2020-11-27 05:19

EDIT: I made something much better to fill and read data from a view using ViewModels, called it ValueInjecter. http://val

4条回答
  •  青春惊慌失措
    2020-11-27 05:46

    In general, I think it looks good, and it's usually a good idea to create viewmodels for your domain objects.

    I haven't looked at every single line of code, but one thing that caught my attention was the constructors of OrganisationViewModel. I'd rewrite it using:

    public OrganisationViewModel() : this(new Organisation()) { }
    
    public OrganisationViewModel(Organisation o)
    {
      Organisation = o;
      InitCollections();
    }
    

    This removes some duplicate code, as you don't have to call InitCollections() in both constructors. Of course, this is just a minor detail, and has nothing to do with the general idea.

提交回复
热议问题