我如何向下面的Razor Helper PagedListPager添加查询字符串?
@Html.PagedListPager( (IPagedList)Model.PartsList, page => Url.Action("Index", new { page }) )
答案 0 :(得分:3)
您不会在PagedListPager
中添加查询参数,而是在Url.Action
中执行这些参数。
以下是您的代码的更新版本,我添加了一个查询参数tag
。
Url.Action("Index", new { page, tag = 'asp' })
该URL将生成以下查询字符串
?page=1&tag=asp
Url.Action
中的PagedListPager
代码相同:
@Html.PagedListPager(
(IPagedList)Model.PartsList,
page => Url.Action("Index", new { page, tag = 'asp' }))
答案 1 :(得分:0)
您只需添加更多查询参数
Url.Action("Index", new { page, tag = "asp", tag1 = "value1", tag2 = "value2" })
URL将生成以下查询字符串
?page=1&tag=asp&tag1=value1&tag2=value2
如果值为空,则查询字符串不包含在生成的URL中
Url.Action("Index", new { page, tag = "asp", tag1 = "value1", tag2 = "" })
?page=1&tag=asp&tag1=value1
非常感谢Yorro!