开发者

mvc selectlist separation of concerns

开发者 https://www.devze.com 2023-03-05 23:38 出处:网络
Shouldn\'t a co开发者_开发百科ntroller in MVC be completely ignorant of how the data it gives to the view will be displayed?

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

精彩评论

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

关注公众号