Put variables in the URL in MVC to use with JS

2

I have a search page that will fetch the results using ajax. Do the searches you do, the URL is always the same, because the page does not change. Is there any way for me to change the URL also when I do the search? Ex: I wanted to have a variable that stored the search keyword in the URL so I could then fetch it in a javascript function. Will it be necessary to change the routing of the controller in question? I work with MVC4 and RazorView, and use JS to implement ajax.

I call this method to search (Material / Index):

public ActionResult Index(Portal.Models.MaterialsAdvancedSearchViewModel advancedFilter, string searchParameter, bool chooseMaterialsSpotlight = false)
    {...}

When searching for something it will run this method (Material / MaterialPagination):

public ActionResult MaterialPagination(int page, int results, string searchParameter, string order_field,
        string order_by, Portal.Models.MaterialsAdvancedSearchViewModel advancedFilter,
        string companyID, bool chooseMaterialsSpotlight = false)
    {...}

In this second method it fetches all the materials I have from the database that match the filters (the input arguments) and places them in a partial view that is loaded using ajax for the view of the first method. I wanted to somehow put those filters in the URL so I could do a search with just the URL. I currently can not go directly to page 5, and if I click on any search result it opens a new window, I wanted to be able to open it in the same window and then go back and stay where it was in the search.

    
asked by anonymous 13.01.2017 / 11:32

1 answer

0

I was able to resolve this situation using the HTML5 History API. For those who do not know, you can check out mozzila's site here .

    
20.01.2017 / 11:48