public ActionResult Index(int id, string name)
{
var model = new ITViewModel
{
Packages = _Repository.GetDeployedPackages(id)
};
return View(model);
}
[HttpPost]
public ActionResult GeneratePackage(ITViewModel model)
{
_Repository.SavePackage(model);
//Generate Zip file Package
//Get file template in archiveStream
Response.Clear();
Response.ContentType = "application/zip";
Response.AppendHeader("content-disposition", "attachment; filename="testzipPackage");
Response.CacheControl = "Private";
Response.Cache.SetExpires(DateTime.Now.AddMinutes(3));
Response.Buffer = true;
var writeBuffer = new byte[4096];
var count = archiveStream.Read(writeBuffer, 0, writeBuffer.Length);
while (count > 0)
{
Response.OutputStream.Write(writeBuffer, 0, count);
count = archiveStream.Read(writeBuffer, 0, writeBuffer.Length);
}
model.Packages = _Repository.GetDeployedPackages(model.id) //get the correct package list with the one tht we just saved on this ActionResult
return View("Index",model);
}
//Index
@model ITViewModel
@using (Html.BeginForm("GeneratePackage", "Integration", FormMethod.Post)
{
//some input form
}
<table>
@foreach (var package in Model.Packages)
{
<tr>
<td>
@package.Name
</td>
</tr>
}
</table>
I am able to download the zip file correctly. In the debugger I also see the Package list with the newly added element. But the View on Post is not getting refreshed. I mean the table on the Index doesn’t refresh with the new model element. Even the document.ready is not getting called once return View("Index",model) is fired.
I have tried ModelState.Clear(). It didn't work.