MVC Filtering, how do you sort artists for a music site by A-Z?
I have made the MVC Music Store through the tutorials and I'm now currently changing and adding 开发者_如何学运维things to the site to my liking. What I'd like to be able to do is open the Artist page and have the letters A-Z and All written across the screen in a bar at the top to allow users to browse Artists by the first letter of the bands name. What method would I use for this? Would a parameter help me?
You can use a parameter to filter data. When you populated model in controller action use default filter parameter as either 'All' or 'A' (first letter). Then filter model data and then return it with view. For 'All' obviously skip filtering logic.
On view you can have ActionLink for every letter linked to same action and passing letter as parameter. This way you can use same action to display data and all you will need action links passing parameter to that action and displaying data will be same (either use webgrid or any other way to display data).
精彩评论