adding variable to pager

May 5, 2013 at 12:15 PM
Hey. I have created a sql based way to search instead of the norm. Its using pager as normal. This is page is /search/?q=thequery then page 2 becomes /search/1 . Is there any way to add the q variable to the pagetr so its /search/1?q=thequery which works when entered directly into address bar

thanks :)
May 5, 2013 at 8:41 PM
I don't understand what you mean...
Currently the route is built using the page and q route values, like this
If you are trying to override the behaviour, maybe you are wrongly configuring the routes.config file....but I don't know...
Could you provide more detail?

Kind regards,
May 6, 2013 at 1:55 AM
i have wrote my own. i didnt like lucane. By using my own version it allows for more functionality. ranked results, latest results, results sorted by ... etc etc

<add url="search/{page}" controller="Search" action="SearchPageDetail">
    <add key="page" value="\d+" />
    <add key="page" value="0" />
#region Search page detail
    public ActionResult SearchPageDetail(string q, int page, string query)
        Forum f = _service.GetAll();
        if (f == null)
            return ResultHelper.NotFoundResult(this);

        f.Search = _topicService.GetSearchByTag("'"+q+"'", Role);

        string q2 = q.Replace(" ", "+");

        ViewData["Page"] = page;
        ViewData["q"] = q;
        ViewData["q2"] = q2;
        ViewData["query"] = query;
        return View(f);

  public List<Search> GetSearchByTag(string q, UserRole? role)
       DbCommand comm = this.GetCommand("SPGetSearchByTag");
       comm.AddParameter<string>(this.Factory, "searchquery", q);
       comm.AddParameter(Factory, "UserGroupId", DbType.Int16, (short?)role);

       var list = ParseSearchForFullList(comm);
       return list;
etc etc. This all works but I have used the pager to page the results using IPagedList but now the pager makes the second page /search/1 and i need /search/1?q=thequery it basiacly works like topics results but for a search using FullTextTable to return most relevent results.
May 6, 2013 at 2:00 AM
ignore the GetSearchByTag name as I was originally going to make searches either for the whole forum or within topics posted with x tag. this has changed but I havnt changed the name
May 6, 2013 at 2:09 AM
i tried every variation of this and it didnt work. should have looked what you used. @Html.Pager(search, new { q = ViewBag.q }, S(" "), S(" ")) made it work perfectly in the view