0

Using ASP.NET Core 2.2 with razor pages... I have a razor page1 which includes a table with lots of integer Id-values from a database. I have to open another razor page via JavaScript and pass all the Ids from page1 to page2. At the moment I do it like this:

window.location.href = "/myUrl/page2?idList=..."

and pass the list of Ids as a JSON-string. This works well until the URL becomes too long (the string for idList becomes too long).

What I need to know: how can I pass a long list of integer values to a razor page via JavaScript without getting in the limit with the URL?

TIA Heiko

4
  • 1
    You shouldn't have to pass all those IDs in the first place I guess? What if you pass some type of information instead that allows the next page to read the relevant values from the DB instead? Anyway, if you really must do this, the answer is to simulate a form submission. Create a <form method="post" action="/myUrl/page2">, append a hidden input containing the list as value with name="iDList", then submit the form by calling submit() on it. The server must process a POST param instead of a GET param, obviously. (but again, this is a bad workaround for what's most likely an xy problem) Commented Jan 15, 2021 at 11:47
  • Thanks for the reply, the workaround is a start. The problem is: I have a grid-component where the user can filter a list of data. Than I have to get all Ids from user selection an pass it to another page. Commented Jan 16, 2021 at 11:36
  • Hi @okieh, "I have a grid-component where the user can filter a list of data. Than I have to get all Ids from user selection an pass it to another page." Do you mean you have to submit the selected Ids to the server side, and filter data based on the Ids? If that is the case, as Chris said, you could submit the a <form> and use a hidden filed to store the Ids, or you could use jQuery Ajax (Post) method. If you just want to share the Ids on the client sides, you could use cookies to store the Ids. Commented Jan 18, 2021 at 9:32
  • I finally implemented the solution with the form and it works! Setting cookies is difficult because of restrictions. Commented Jan 21, 2021 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.