【发布时间】:2015-10-07 19:13:00
【问题描述】:
这将在按下按钮时发送一封电子邮件。但是,我试图在重定向回按钮页面之前调用 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");
}
【问题讨论】:
-
如果你想在 AddColiform 重定向后只下载文件调用 SaveDocument
-
那么您是说将“SaveDocument()”调用放在“AddColiform”ActionResult 的开头?我将不得不发送一个标志,因为大多数时候没有理由“SaveDocument()”。仅当样本是检测时。我会试试的,但今天我下班了。待命,谢谢。
-
在 AddColiform 中重定向后无法调用 SaveDocument。一旦调用了重定向,之后就无法运行任何东西。我尝试过这个。我试着把它放在 AddColiform 的顶部,也不管用。
标签: asp.net-mvc-4 controller redirecttoaction fileresult