I need help to accomplish this task: download an XML file (with the prompt to select a path and a name of the file) using Jquery to receive an XML from the backend (asp MVC). Tried to remove [HttpPost], don't return any view, and I don't have more ideas to try. I researched a lot and found some solutions but none works. When I executed this code nothing happen. Some ideas? EDITED: The steps I want to do when I click a button, open the prompt, write a name and select a path and download the file in the browser.
I have this javascript:
$('#exportButton').on("click", function () {
var clientName = $(actionsButtons).data('clientname');
var currentHCSystem = $(actionsButtons).data('hcsystemname');
var clientConfig = false;
var fileConfig = false;
// Create FormData object
var parameters = new FormData();
parameters.append("clientName", clientName);
parameters.append("currentHCSystem", currentHCSystem);
$.ajax({
url: $(actionsButtons).data('export'),
type: 'POST',
data: file,
cache: false,
processData: false,
contentType: false,
success: function (response) {
//??
},
error: function (err) {
//??
}
});
});
and MVC
[HttpPost]
public ActionResult ExportFiles(string clientName, string currenthcsystem)
{
try
{
var systemActionsConfigurationData = service.GetHcSystemActionsConfigurationData(currenthcsystem);
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename = itfunda.xml");
Response.ContentType = "text/xml";
var serializer = new XmlSerializer(systemActionsConfigurationData.GetType());
serializer.Serialize(Response.OutputStream, systemActionsConfigurationData);
return View("Index");
}
catch (Exception)
{
throw;
}
}