I’m relatively new to using the MVC pattern and this is my first SO question; I’m specifically using ASP.NET MVC 3, but my question could apply to the general MVC pattern. What is the best way to reuse controller methods that essentially return the same View, but may have different result sets queried from the database? For example, I may want to show all customers, or some customers in a specific regions, or some customers that have an “elite” status.
I currently have separate controller methods for each of these “GetBy…” result sets. Is there a way to use a “List” controller and populate it with different result sets? Perhaps by injecting the result set as a parameter?
Keep those methods in a service layer and call it based on the input requirement. Check the parameters passed to the action method.
And your view will be bounded to a collection of Customer object
Assuming
GetCustomersForRegionStatus,GetCustomersForRegionandGetAllCustomersmethods returns a List of Customer object and internally it calls different DB access method to get the filtered data based on the parameters being passed.These for urls requests will give different results now.