0

I'm trying to make my view work, how it works is you can select a number of different branches which will then be used to filter the search results. Now this works fine when I hit the filter button,

Here is the query string

/Search?Ref=&Keyword=&StartDate=&Branches=3299374&Branches=38087&Branches=38090&Branches=38093&Branches=38095

But when I click on the pager to go to another pager the query string changes to this

/Search?Branches=3299374%2C38087%2C38090%2C38093%2C38095&page=2

How can I stop the pager from doing this? I think it is encoding my query string, but i'm not 100% sure.

Also I have tried to create a shape view called Pager_Next.cshtml

@{
    var pBranches = Request.QueryString["branches"];
    var RouteValues = (object)Model.RouteValues;
    RouteValueDictionary rvd;
    if (RouteValues == null) {
        rvd = new RouteValueDictionary();
    }
    else {
        rvd = RouteValues is RouteValueDictionary ? (RouteValueDictionary)RouteValues : new RouteValueDictionary(RouteValues);
    }
}
<a class="newer" href="@Url.Action((string)rvd["action"], rvd)">Newer articles</a>

But this still has the same results

tereško
  • 58,060
  • 25
  • 98
  • 150
Canvas
  • 5,779
  • 9
  • 55
  • 98
  • Possibly relevant: http://stackoverflow.com/questions/11621477/using-duplicate-parameters-in-a-url. `%2C` is a comma, and blank parameters are equivalent to non-existent ones. – Bobson Apr 29 '14 at 14:42

1 Answers1

1

Just to let anyone else know if they are having problems with this. I created a model binder,

The ModelBinder code looks like this 

    public class CommaSeparatedLongArrayModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var values = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
            if (values != null && !string.IsNullOrEmpty(values.AttemptedValue))
            {
                // TODO: A minimum of error handling would be nice here
                return values.AttemptedValue.Split(',').Select(x => long.Parse(x)).ToArray();
            }
            return base.BindModel(controllerContext, bindingContext);
        }
    }

and in my controller I use this

Binders[typeof(long[])] = new CommaSeparatedLongArrayModelBinder();
Canvas
  • 5,779
  • 9
  • 55
  • 98