pavel
pavel

Reputation: 187

Get many filter parameters

I have a grid in which, I load data from database. I need to create filter on each column in the grid. It's about 12 columns and I don't want pass all my filter parameters through my function.

public ActionResult Index(int? StationCategory, int? StationPosCountry, 
      GridSortOptions gridSortOptions,   int? page, int? pageSize .........)
    {

    }

I also view that parameters can be read in this way:

    var request = Request.QueryString.ToRouteDic();

request would contain, two collections Keys and Values, it more comfotable for me, but may be this keep hidden danger. My question is in witch way, it's better pass many filter parameters?

Upvotes: 2

Views: 362

Answers (1)

Kaido
Kaido

Reputation: 3981

You can put all those parameters into a class

public class GridParameters 
{ 
public int? StationCategory {get;set;} ... 
}

then use that object as input and mvc should simply bind them to the properties with the same name

public ActionResult Index (GridParameters formModel)

Upvotes: 1

Related Questions