Aflred
Aflred

Reputation: 4593

Create querystring list with IpagedList

in the controller i have:

int[] numbers = {1, 2, 3}; 
ViewBag.List = numbers;

then in the view i do this:

@Html.PagedListPager(Model, 
page => Url.Action("Index", new { page, new[] = ViewBag.List  }))

I want it the pagedlistpager to produce a link like this:

/?numbers=1&numbers=2&numbers=3

in other words how would i just

Url.Action("index", new { [] numbers = Viewbag.List})

something like that im not sure how to deal with syntax.

obviously that code is wrong because i cant have [] in an anonymous type but maybe somebody can help me out with something similar or a solution to produce that link from viewbag.

IM USING ASP.net MVC 4.

Upvotes: 1

Views: 1050

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038780

A bit ugly but might work:

@Html.PagedListPager(
    Model, 
    page => 
        Url.Action("Index", new { page = page }) + 
        "&" + 
        string.Join(
            "&", 
            ((int[])ViewBag.List).Select(x => "numbers=" + Url.Encode(x.ToString()))
        )
)

As an alternative to writing this soup, you could write custom HTML helper that will take care of that.

Upvotes: 4

Related Questions