Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Istvan Pszota 59 posts 191 karma points
    Aug 23, 2019 @ 05:36
    Istvan Pszota
    0

    Listing page with filter and pagination

    I have to create a listing page as follows: Current page id is shown in QueryString and the listing page have filter and keyword search functionality.

    The result is filtered and can be searched without problem, but when i redirect to another page (2. or 3. or 4. of the results) the filters are cleared.

    I have created a partial view (that holds the form and the Razor logic) what is displayed via RenderAction in the template. The filter criteria (except the current page id) is handled between the View and the Controller in a Model, while the current page id is updated through QueryString.

    I understand that the Model (filter criteria) is cleared because the Model is cleared during redirection, but i have absolutely no idea how to update the QueryString from Controller + keep the Model data present..

    Template file:

    @{ Html.RenderAction("RenderPageWithSearch", "ContentListingSurface"); }
    

    Partial View

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentListingSurfaceCriteriaModel>
    @using Umbraco.Web
    
    @using (Html.BeginUmbracoForm("RenderPageWithSearch", "ContentListingSurface", System.Web.Mvc.FormMethod.Post))
    {
       ...
    
    
       ...
    }
    

    Controller

    public ActionResult RenderPageWithSearch(ContentListingSurfaceCriteriaModel criteria)
    {
    
    }
    [HttpPost]
    public ActionResult RenderPageWithSearch(ContentListingSurfaceCriteriaModel criteria, string submitFrm, string p)
    {
       //submitFrm - to determinate which submit button was pressed
       //p - the current page id
    
      //Querying and filtering the data
    
      return RedirectToCurrentUmbracoPage("p=" + pageID);
    }
    

    I do not have much experience with MVC so this info might only be important notice for me: when i submit the form the Model contains all the filter criteria info, no matter how many times i update the filters, the result is updated accordingly. I understand that as the Controller redirects to a new page, the Model is cleared. My goal would be to keep the filter criteria in the model when i redirect to for example the next page.

    Any help / advice would be highly appreciated as this problem almost drives me crazy..

    If any more detail of the code is necessary, let me know and i will post it.

  • Jonathan Distenfeld 105 posts 618 karma points
    Aug 23, 2019 @ 06:31
    Jonathan Distenfeld
    100

    Hi Istvan,

    have you already thought of adding a cookie containing the filter values? You could check for this cookie and update it when the filter changes.

    ~ Jonathan

  • Istvan Pszota 59 posts 191 karma points
    Aug 23, 2019 @ 06:37
    Istvan Pszota
    0

    Hi!

    And after i do a redirection to another page of the result, during loading the form i should check if the filter values are present and set the filter values accordingly? And if the values are not present, then the user probably remained on the same page but modified the filters?!

    Or, completely forgot to use the Model to maintain the filters and only use Cookies?

    This just came into my mind a couple of minutes ago, but i was wondering of this is the solution? :)

    Regards, Istvan

  • Jonathan Distenfeld 105 posts 618 karma points
    Aug 23, 2019 @ 06:57
    Jonathan Distenfeld
    0

    If I understand you correctly, everything works fine if the User stays on the result-list page right? The problem you have, only appears if the user goes to another page?

    Then I would suggest to check for the cookie if your model is empty before loading the form and fill the model with the filter values in the cookie. Then, when the user changes the filter, you would update the cookie in your controller-action.

    Is this a solution you could go with?

  • Istvan Pszota 59 posts 191 karma points
    Aug 23, 2019 @ 08:03
    Istvan Pszota
    0

    Yes, you are correct.

    I did not know that it is possible to modify the value of a controller which is on a view and binded to a Model from cookie?!

    I will give that a try now and will revert asap!

    Many thanks, Istvan

  • Istvan Pszota 59 posts 191 karma points
    Aug 27, 2019 @ 17:25
    Istvan Pszota
    1

    Thanks Jonathan!

    I've a made a workaround using cookies.

    It is not the nicest solution, but seems to do the job.

    Regards, Istvan

Please Sign in or register to post replies

Write your reply to:

Draft