【问题标题】:Url appending 2nd querystring when using @Html.PagedListPager使用 @Html.PagedListPager 时附加第二个查询字符串的 URL
【发布时间】:2013-02-27 09:30:16
【问题描述】:

有谁知道如何解决这个问题,我有一个搜索框,当我输入搜索短语并提交表单时,网址是:

http://localhost:50435/Search-Results-For?q=hotels&Option=Web&Page=1

返回结果后,我就可以分页了,url是:

http://localhost:50435/Search-Results-For/hotels/web/2

但如果我随后尝试进行另一次搜索,则该搜索会附加到上面的 url:

http://localhost:50435/Search-Results-For/hotels/web/2?q=poole&Option=web&Page=2

我不知道如何解决这个问题,我尝试将寻呼机放在部分视图中,更改参数但似乎没有任何效果。

以前有没有人遇到过这个问题或知道如何解决。

寻呼机:

<div id="dvPagePager">@Html.PagedListPager((IPagedList)ViewBag.SearchResults, page => Url.Action("Results", new { Page = page, q = @ViewBag.q, Option = @ViewBag.b}), PagedListRenderOptions.OnlyShowFivePagesAtATime)</div>

表格:

@using (Html.BeginRouteForm("SearchEngine", FormMethod.Get, new { @id = "frmSearchEngine" }))
                                    {
                                   { Html.RenderAction("pvSearchForm", "Home"); }
                                   //Html.RenderPartial("~/Views/Shared/pvSearchForm.cshtml");
                                    }

路线:

routes.MapRoute(
                name: "SearchEngine",
                url: "Search-Results-For/{q}/{Option}/{Page}",
                defaults: new { controller = "Search", action = "Results", q = UrlParameter.Optional, Option = UrlParameter.Optional, Page = UrlParameter.Optional }
            );

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing


    【解决方案1】:

    通过使表单成为标准的 html 表单解决了这个问题,添加了一个带有 http 的 URL.Action,这会在做新帖子时强制刷新 url

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-27
      • 2013-05-27
      • 2015-02-02
      • 1970-01-01
      相关资源
      最近更新 更多