I have a
Filter
public class Filter
{
public int FilterId { get; set; }
public ICollection<int> ModuleIds { get; set; }
}
public ActionResult Navigate
{
var filter = new Filter()
{
FilterId = 5,
ModuleIds = new List<int>() { 6 };
}
return RedirectToAction("list", "user", filter);
}
public ActionResult List(Filter filter)
{
var filterId = filter.FilterId; // = 5
// but filter.ModuleIds.Count = 0
}
filter.ModuleIds
filter
TempData
return RedirectToAction("list", "user", new RouteValueDictionary(filter);
return RedirectToAction"list", "user", new { filter = filter} );
You can't pass reference types. The reason is that RedirectToAction
doesn't serialize the data, it simply iterates over the properties in the route values object constructing a query string with the keys being the property names and the values the string representation of the property values. If you want to have the Url
change, then using TempData
is probably the easiest way to do this.