Model view controller 数据问题
在那里; 我的MVC项目中有一个非常奇怪的Tempdata问题。这是我的伪代码Model view controller 数据问题,model-view-controller,Model View Controller,在那里; 我的MVC项目中有一个非常奇怪的Tempdata问题。这是我的伪代码 public class MyController: Controller { public ActionResult CreateInvoiceAndCustomerContact() { return View(); } [HttpPost] public ActionResult CreateCustomerContact_Invoice()
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”]”就没有问题
谁能帮我一下吗
干杯
Rob。在ASP.NET论坛上搜索并提问后,我终于解决了这个问题: 我将我的文本文件写入“BIN”文件夹,从而导致应用程序池重新启动!!!见链接: 这就是我丢失临时数据的原因。通过更改文件位置,现在一切正常 干杯
Rob我还尝试了另一个代码测试:public ActionResult TestTempData(){using(System.IO.StreamWriter writer=new System.IO.StreamWriter(@“D:\folder\sth.txt”){writer.WriteLine(“sth!!!”);}TempData[“Message”]=“TestMsg”;返回重定向到操作(“LoadInvoiceAndCustomerContact”);}此消息无法显示在视图上。如果我删除“使用”块,则显示消息不会有问题。有人可以对此进行解释吗?Chees,Robert