I have a search forms with pages that return a calendar. In top I have some search criteria and it all works fine if it’s only one value but not if it’s a list. When I want to build the url for the next month in my model I have something like this :
public ActionResult GetUrl()
{
var action = GetBaseAction();
if (SelectedDivisions.Any()) action.AddRouteValue("SelectedDisions", SelectedDivisions.ToArray());
if (RoomId.HasValue) action.AddRouteValue("RoomId", RoomId.Value);
if (TeacherId.HasValue) action.AddRouteValue("TeacherId", TeacherId.Value);
if (Month.HasValue) action.AddRouteValue("Month", Month.Value);
if (Year.HasValue) action.AddRouteValue("Year", Year.Value);
if (Day.HasValue) action.AddRouteValue("Day", Day.Value);
return action;
}
Wich add the parameters to the next month URL :
http://afi.local/coursesession/calendar?Month=9&Year=2012&Day=18&ViewType=weekly
but since you can select more than one division, it’s a list of checkbox so when I post my form, I get this URL :
The problem is that if I add 2 times the same keys it throw an exception and I don’t know how to rebuild my URL with more than one division in the query string.
Thanks for the help!
I found a solution here : https://stackoverflow.com/a/717732/245836
Basicly what I do is this :
And the resulting URL is not very clean but the bindings works fine :
http://afi.local/coursesession/calendar?SelectedDivisions%5B0%5D=1&SelectedDivisions%5B1%5D=2&SelectedDivisions%5B2%5D=3&Month=9&Year=2012&Day=11&ViewType=weekly
So now I can copy paste that URL and it will work for any search in my calendar.