Using HttpGet from ASP.NET Core API Endpoint with search parameters to populate a datatable

Using HttpGet from ASP.NET Core API Endpoint with search parameters to populate a datatable

Jeffrey ZolaJeffrey Zola Posts: 4Questions: 2Answers: 0

I am trying to set up an ASP.NET Core MVC View that includes a table to show search results. I want this table to be sortable & paginated using the DataTables plugin, and I need to define search parameters OUTSIDE the definition of the HTML table.

I want to use RESTful HTTPGET requests for the raw data because I want to take advantage of the fact that the browser can store their results in cache and reuse them if allowed by the headers.

All viable examples of using DataTables (and other table/grid "helpers", in fact) use HTTPPOST requests to "get" data. I get it. It's easier to embed a search model, etc., in the body payload of a POST than to include complex search parameters and table metadata in the query string of a GET. But the response of an HTTPPOST can never be cached by a browser client. So it will always need to submit a request and receive a full response (never an HTTP304).

I can have the server cache raw query results (and will need to do so to allow it to reuse the "raw" search results before server-side sorting & pagination are applied. But the server will still need to return full HTTP200's with the appropriate datasets instead of enabling the browser to bypass the server if allowed by the Cache-Control headers on a previous response.

Has anyone else encountered this?

Answers

  • allanallan Posts: 63,572Questions: 1Answers: 10,482 Site admin

    All viable examples? This one doesn't it is GET based. Indeed, the default request that DataTables makes is GET. You would need to specify the type: 'POST' option in ajax if you wanted to send a POST request.

    The advantage of POST is that you can send much more data. It also bypasses cache which is useful in some cases and not in others like your own.

    So I guess what I'm not clear about is why the examples such as the one linked to isn't "viable"?

    Allan

Sign In or Register to comment.