I'm implementing the following scenario:
There is view with a catalogue of items (like products) and a filter for them. Filter is a list of checkboxes and each of the checkboxes represents one category for an item. The number of categories is not fixed.
In my controller I get all the date for the filter with the following method:
[AcceptVerbs(HttpVerbs.Post)]
public RedirectToRouteResult List(int? page, FormCollection formCollection)
{
IEnumerable<int> categoryFilter = selectFilterIDs(formCollection, "category"); //parsing the Form Collection object
return RedirectToAction("List",
new
{
page = 1,
filterCategoryIDs = categoryFilter
});
}
this method passes all the data to:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult List(int? page, IEnumerable<int> filterCategoryIDs)
{
//restore selected and unselected values
ViewData["selectedCategories"] = filterCategoryIDs;
.............
}
So after the redirect I get an empty IEnumerable<int> filterCategoryIDs. It is not equal to null, it is just empty.
The same happens when I try to pass data from my view when making the pagination:
<%= Html.Pager(
ViewData.Model.PageSize,
ViewData.Model.PageNumber,
ViewData.Model.TotalItemCount,
new { filterOrderTypeIDs = ViewData["selectedOrderTypes"], filterCategoryIDs = ViewData["selectedCategories"] })
%>
So the question is how to pass collections as parameters properly