Reputation: 27703
The well described model of View/Controller/Model is quite clear when it comes to object (say a book) update/delete/save etc., but how do you organize the common code such as populating drop down lists (from db)?
I use jQuery ajax to call control's action, but in cases such as getting the arrays for drop down lists, I feel like these should not reside in the same BookController.
Can I have a Controller without the matching view for these purposes only?
Upvotes: 0
Views: 135
Reputation: 54618
Each ViewModel
is data for a View
to render. It sounds like you understand that. When Ajax calls for Data, I think it makes more sense for the controller for the view be responsible for creating another ViewModel
and returning it as Json for the rendered view. If mutliple views need to retrieve a list of Books, should call /Books/AjaxList
(bad method name example), just like any view under /Books
. Seperating the responsibility of creating a ViewModel
based on Ajax or not Ajax doesn't make sense to me.
Upvotes: 1