Best way to post asp.net-mvc page using POST

I have an action method that returns a PagedList <after a form POST request.
I would like to add paging to this page, but all the paging scripts seem to only work with GET requests.

Currently, the only way to add paging controls is to add a single button form group to navigate the page. It will look, but ugly (all form buttons) and impose a lot of overhead, because each of the forms will need a bunch of hidden fields (about 10) to pass the required parameters.

Is there a clean way to add about 12 optional parameters to a GET request? Or maybe there is an even better way?

+1


source to share


2 answers


Each page button has one unique value that must be submitted along with the rest of your form values. So you really need something like:



function GoToPage(pageNumber)
{
    // submit form along with pageNumber

    return false;
}

<a href="javascript:GoToPage(1);">1</a>
<a href="javascript:GoToPage(2);">2</a>
<a href="javascript:GoToPage(3);">3</a>

      

+1


source


The way to add many optional parameters to a GET request is to use query string parameters. Make the arguments for your controller action zero and the MVC framework will populate them with query string parameters if the user supplies them, and leave them otherwise.



I don't think using POST for paging is generally appropriate. POST is for updating a server resource. Paging does not.

0


source







All Articles