ASP.NET MVC Filtering results in a list/grid

前端 未结 6 1871
我寻月下人不归
我寻月下人不归 2020-12-28 21:32

For some reason I\'m stuck on this. I need to filter results from a View based on a DropDownList in the same view. The basic idea is this: I have a list of providers that be

6条回答
  •  半阙折子戏
    2020-12-28 22:36

    Let's assume that you're probably passing a model to the view and that model is a list or IEnummerable of partners. What you want to do is restrict the list. In order to do that add a drop down list in the view and fill it with some possible partners. This can be done either by putting a list in ViewData or expanding the model passed back to the view. Both have advantages. Now when you change the drop down reload the page but append a parameter which is the filter. In the controller check for that parameter in the action, if it isn't present then return an unfiltered list, if it is then apply a filter and return the list. The view will just dumbly display whatever you give it.

    As for the filtering you might want to try using LINQ.

提交回复
热议问题