在这里,我在MVC项目中遇到了一个非常奇怪的Tempdata问题。这是我的pseudoCode;
public class MyController: Controller
{
public ActionResult CreateInvoiceAndCustomerContact()
{
return View();
}
[HttpPost]
public ActionResult CreateCustomerContact_Invoice()
{
{
_MyFileCreationObj.CreateTtextFile();
}
TempData["ResultMessage"] = "hello";
return RedirectToAction("CreateInvoiceAndCustomerContact");
}
}
In object _MyFileCreationObj I have a method which uses "StreamWriter" to create text file:
public void CreateInvoiceAndCustomerContact()
{
using (StreamWriter writer = new StreamWriter(exportedFile))
{
//write text to a file
}
}我遇到的问题是:"TempData"ResultMessage"“无法在我的视图中显示。
如果我注释掉了StreamWriter块,那么在我的视图中显示“TempData”“ResultMessage”是没有问题的。
有人能帮帮忙吗?
干杯罗布。
发布于 2015-08-07 09:45:38
在ASP.NET论坛上搜索并提问后,我终于解决了这个问题:我将文本文件写入"BIN“文件夹,导致应用程序池重新启动!请参阅链接:Common reasons why your application pool may unexpectedly recycle,这就是我丢失TempData的原因。通过更改文件位置,现在一切都可以正常工作。
干杯抢劫犯
https://stackoverflow.com/questions/31376174
复制相似问题