Still new to ASP MVC development.
Suppose I have a MusicController that has 2 views: List (which shows a list of all artists) and Highlights (which shows 3 specific albums with all details).
I now want to render both views on one page.
1) What is the best way to do this? Partial views? Do I need to make a separate controller for the page that shows both partial views?
2) Suppose I want to change the highlights based on the selected artist. How to pass that parameter to the partial view with highlights?
Thanks for giving me some leads!
Partial views is indeed what you want. One bit of trouble that you might run into is that sometimes it’s hard to make a partial view that works as both stand-alone and embedded in another view. The solution is to create a separate view that contains all the necessary boilerplate that then calls the (single) partial view. Then the partial views are suitable to be used in both the individual pages and the combined page.
You don’t need a separate controller for your aggregate view, but it will need its own action.
So here’s the structure I’m advocating:
In
MusicController:The views for
ListandHighlightswould look something like this:And
ListAndHighlights()would look something like this:If you want the partial views to update in response to something on the client side, you’ll have to use AJAX.