In short, we have special requirements. That is, to put certain data into form elements, and then submit the form. The reason we do this is to open a new window to return the Excel spreadsheet, but we need to specify the parameters for the form request.
Basically, my data (clickPoints variable in javascript) is not passed to the server side action method, but is in the form request.
Properly:
$("#excel").click(function() { $("#Points").val(getExcelDataPoints(clickPoints)); $("#GeomType").val("LINESTRING"); $("#StartDate").val($("#start-date").val()); $("#EndDate").val($("#end-date").val()); $("#ExcelExport").submit();
All other parameters work fine, except for points. Here is the definition of getExcelDataPoints
function getExcelDataPoints(points) { var data = "{'Points': ["; for(var i = 0; i < points.length; i++) { data += "{'Da': '" + points[i].lat() + "', 'Ea': '" + points[i].lng() + "'},"; } data = data.substr(0, data.length - 1); data += "]}"; return data; }
You might be wondering why I build it manually. There are reasons. The thing is, this definitely works when executing a $.ajax request using jquery, so I know that the format is absolutely right. But when executing the first code, as indicated above, it does not work.
Here is the definition of the action on the server;
[HttpPost] public IList<AISExcelPosition> ExcelExport(LatLng[] Points, GeomType GeomType, DateTime StartDate, DateTime EndDate) { var poo = Request.Form["Points"]; // Magical.... UNICORNS! /* `\ \\, \\\,^,.,,. ,;7~((\))`;;,, ,(@') ;)`))\;;', ) . ),(( ))\;, /;`,,/7),)) )) )\,, ,,,... , (& )` (,((,((;( ))\,_,,;'` `\\, `" ` ), ))),/( ( `)\, '1/';/; ` ))), (, ( / ) ((/, / \ / (((' ( 6--\% ,> ,,,( /'))\' \,\,/ ,/`----~`\ \ >,))))' \/ / `--7>' /(((((' (,9 // /'('((\\\, \ \,, (/,/ '\`\\'\ `\_)1 (_)Kk `\`\\`\ `\| \Z `\ ` " ` */
Yes. In my code, I have a unicorn.
You will see a bit var poo = Request.Form["Points"]; that we launched there, which proved to us (and after observing the form data in the basic POST request) that the data is really there, everything is beautifully formatted.
Here's the actual JSON data:
"{'Points': [{'Da': '49.45995313552066', 'Ea': '-2.5134216308593977'},{'Da': '49.45894893804116', 'Ea': '-2.5134216308593977'}]}"
Any clues on what I should do?