当按下按钮时,这将发送一封电子邮件。但是,我试图在重定向回按钮页面之前调用 FileResult、SaveDocument 来下载文件。
为了测试,我现在使用硬编码文件下载。我可以使用测试按钮运行 SaveDocument() 结果。我无法发送电子邮件、运行 SaveDocument 操作然后重定向。
[HttpGet]
public ActionResult send(int thisbatch, string listofpositives)
{
MailMessage mail = new MailMessage();
SmtpClient smtpServer = new SmtpClient("smtperServer");
smtpServer.Port = 25; // Gmail works on this port
smtpServer.EnableSsl = false;
mail.From = new MailAddress("xxxe@xxx.com");
mail.To.Add("xxxe@xxx.com");
mail.Subject = "Batch Closed";
mail.Body="some info stuff here";
smtpServer.Send(mail);
SaveDocument();
return RedirectToAction("AddColiform");
}
//THIS WORKS BY ITSELF CALLED FROM A BUTTON
public FileResult SaveDocument()
{
string filePath = Server.MapPath("~/XML_positives/Test1.xml");
string contentType = "text/xml";
return File(filePath, contentType, "Test1.xml");
}