In the view I have the following code:
$("#btn_descargar").click(function (e) {
e.preventDefault();
debugger;
var iBody = $("#iframeID").contents().find("body");
var myContent = iBody.find("#myContent").text();
var url = '/Factura/DescargarXML?textoXML=' + myContent + '';
window.location.href = url;
});
In the controller:
public ActionResult DescargarXML(String textoXML)
{
byte[] arr = System.Text.Encoding.ASCII.GetBytes(textoXML);
var fileStreamResult = File(arr, "application/octet-stream", "DTE.xml");
return fileStreamResult;
}
But when the variable myContent (string that I sent as a parameter) contains characters like '<' or '>' (without quotes), it does not work for me. In this case I wanted to send a string that contained the following:
<?xml version="1.0" encoding="ISO-8859-1"?>
<EnvioDTE version="1.0" xmlns="http://www.sii.cl/SiiDte"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd">
<SetDTE ID="ID78450470-0__1__33__137175">
I have tried to convert it to binary (byte []) in the view with javascript, but in doing so, it is separated by commas, which is impossible to receive parameters by commas in controller, since it says it can not find the resource.
The purpose of why I use window.location.href, is to download documents, in this case an xml.
If anyone has any idea how to send this data, I would really appreciate it