Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Model view controller 数据问题_Model View Controller - Fatal编程技术网

Model view controller 数据问题

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()

在那里; 我的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”]”就没有问题

谁能帮我一下吗

干杯
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