I'am trying to create and download a XML from the database. I have this code in my controller
public void ExportListToXML()
{
var data = db.correct.ToList();
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment; filename=itmyfile.xml"); Response.ContentType = "text/xml";
var serializer = new
System.Xml.Serialization.XmlSerializer(data.GetType()); serializer.Serialize(Response.OutputStream, data);
}
And this code/link in my view
@Html.ActionLink("Export to XML", "ExportListToXML")
No errors in the code.
I can run the project without errors.
But I get the error message "System.InvalidOperationException was unhandled by user code" when I click the link. See screenshot.