开发者

mvc selectlist separation of concerns

Shouldn't a co开发者_开发百科ntroller in MVC be completely ignorant of how the data it gives to the view will be displayed?

My question relates to the SelectList. Should the controller be clever enough to know that the data will be presented in a drop down? Or should it simply give the view, through the view model, a list of items, and let the view handle it however it needs?


Absolutely - the controller is responsible for passing the correct data in the correct structure, but doesn't give a monkeys about how it looks. The view could choose to display each list item in a random location if it wanted to - the controller shouldn't be involved in visual logic. Otherwise, as you say, you lose the 'separation of concerns'.


I see what you are getting at. It just depends on how you look at the SelectList. The select list is really just a data structure optimized for this specific use. You could actually use the SelectList for something else if you wanted. In this sense, there is still a clear separation of concerns.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜