有; 我的MVC项目中有一个非常奇怪的Tempdata问题。这是我的伪代码;
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"]"在我看来。
有人可以请帮忙吗?
干杯 罗布。
答案 0 :(得分:0)
After googling and asking question in ASP.NET forum, I finally fixed the issue: I write my text file to the "BIN" folder which causes the restart of the application pool!!! See link: Common reasons why your application pool may unexpectedly recycle That why I lost my TempData. By changing the file location, everything works now.
Cheers Rob