Download_DelegateReportData
is not an action, so you cannot redirect to it.
You should also avoid using
Response.Write
inside an action method. Use an appropriate action result instead.
And you're not sending an Excel file; you're sending a tab-separated values file. You need to use the correct MIME type.
[HttpGet]
public ActionResult Download_DelegateReportData()
{
using (var cb = new eNtsaRegistration_2())
{
var data = (from ... ).ToList();
var b = ConvertToDataTable(data);
var ms = new MemoryStream();
using (var writer = new StreamWriter(ms))
{
writer.WriteLine(string.Join("\t", b.Columns.Cast<DataColumn>().Select(c => c.ColumnName)));
foreach (DataRow dr in b.Rows)
{
writer.WriteLine(string.Join("\t", dr.ItemArray));
}
}
ms.Seek(0L, SeekOrigin.Begin);
return new FileStreamResult(ms, "text/tab-separated-values")
{
FileDownloadName = "eNtsaTraining-Registration.tsv"
};
}
}