0

I have set a ViewBag, which is not displayed in View. Following is my code :-

Response.BufferOutput = false;
Response.ContentType = "application/zip";
Response.AddHeader("content-dispostion", "filename=text.zip");
Response.Charset = "";
using (ZipFile zip = new ZipFile())
{
      foreach (var item in List)
      {
            zip.AddFile(Server.MapPath("~/" + item.Code.ToString() + ".pdf"), "/");
      }
      zip.Save(Response.OutputStream);
}

Response.Close();
ViewBag.Message = "Success";
return View();

If I comment the Response Code & Just set ViewBag & return View() then ViewBag value is displayed in View.

How to get value of ViewBag after Response.Close()?

tereško
  • 58,060
  • 25
  • 98
  • 150
Anup
  • 9,396
  • 16
  • 74
  • 138
  • Should you not set the ViewBag.Message before you close the response? Also, I wouldnt use the ViewBag in this case, I'd use TempData["Message"] = "Success". – Derek Feb 27 '15 at 09:02
  • @Derek Before Closing also didn't display it..~ – Anup Feb 27 '15 at 09:05
  • pls check the link http://stackoverflow.com/questions/3219701/asp-net-response-close-issue – Veena Feb 27 '15 at 09:07
  • Youneed to step through your code, are you exception handling, is the Action dropping out before it can set the Viewbag.. Are you being presented with the new VIew(new request), – Derek Feb 27 '15 at 09:10

0 Answers0