开发者

Is ViewModel appropriate for simple view related logic?

I have a simple partial view which displays a drop down list of revisions for a given entity. The entity contains 2 lists of revisions which can contain duplicates and are not ordered.

For the view I need to display a single combined list from the 2 list of revisions, ordered by Date.

Currently the entity is used as the view model and the code to combine/remove dupes/order was included in the view itself.

I am considering refactoring this by creating a ViewModel which will 开发者_如何转开发contain the entity and provide a public method returning the combined/dupe free/ordered list.

This has the advantage of being testable and simplifying the view to an iteration over a Model.RevisionList property.

This is not domain logic but it should be tested and requirements may change - so does such code belong in a ViewModel and is this a reasonable way to use one?


Yes. That's exactly the use-case for ViewModels.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜