问题
How would I go about adding a query string to the Razor Helper PagedListPager below ?
@Html.PagedListPager( (IPagedList)Model.PartsList, page => Url.Action("Index", new { page }) )
回答1:
You don't add query parameters in PagedListPager
, you do them in Url.Action
.
Below is an updated version of your code, I've added a query parameter tag
.
Url.Action("Index", new { page, tag = 'asp' })
The URL would generate the following query string
?page=1&tag=asp
Here is the same Url.Action
within PagedListPager
:
@Html.PagedListPager(
(IPagedList)Model.PartsList,
page => Url.Action("Index", new { page, tag = 'asp' }))
回答2:
You simply add more query parameters
Url.Action("Index", new { page, tag = "asp", tag1 = "value1", tag2 = "value2" })
The URL would generate the following query string
?page=1&tag=asp&tag1=value1&tag2=value2
If a value is null the query string is not included in generated URL
Url.Action("Index", new { page, tag = "asp", tag1 = "value1", tag2 = "" })
?page=1&tag=asp&tag1=value1
Many thanks to Yorro!
来源:https://stackoverflow.com/questions/23463685/how-do-i-add-a-querystring-when-using-the-mvc-pagedlist