ASP.NET MVC terminology is tripping me up - why 'ViewModel'?

前端 未结 5 493
你的背包
你的背包 2020-12-14 12:45

I\'m an ASP.NET MVC newbie, but have used many Model-View-Controller frameworks previously.

I recently came across the convention of gathering up the pieces of data

5条回答
  •  -上瘾入骨i
    2020-12-14 13:41

    The model is a view-agnostic representation of the data. The view model is a view-specific representation of the data: it's the model as it might appear from a given viewpoint.

    Consider a model that consists of raw data points; a histogram view might then have a view model consisting of a set of buckets and totals drawn from that data.

    Logically, it's a subset or transformation of the model - it could be generated on-demand with a view-specific function and the model as its only input.

    Regarding properties on the view vs. a property bag or custom object... I'm sure someone has strong feelings on this, but personally I don't see the big difference. You're producing a view-specific representation of the model and passing it somehow; the exact mechanism doesn't seem all that important.

提交回复
热议问题