How to: Send JSON structure to server and return file in ASP.NET
I'm having a very hard time wrapping my head around this problem (it might be the heat from the summer finally arriving).
Problem:
I want the user to press a button client side which performs javascript data preparing and at last send a JSON structure to (currently a asmx webservice on) the server. The JSON structure is several levels deep.Server side I create a PDF file which I want to send back to the user.
Goal:
The user feeling is that she presses a button and expects a PDF to return to her - either in a new window or as开发者_开发知识库 a download (preferrable).Tools:
The system consists of (client side) HTML, JavaScript and ExtJS and (server side) ASP.NET.Normally I would use an ashx handler to return a file to the client, but can I send a JSON structure to the handler and still be able to parse it correctly server side?
I am searching for the pattern to use.
On the client side: submit the JSON string as part of the form data.
On the server side: parse the JSON string (the answers to this question list a number of JSON parsers usable in asp.net) and then generate the PDF. The header
Content-disposition: attachment; filename=something.pdf;
will make the PDF appear as a download for the user.
精彩评论