Hello all,
I am just simply trying to pass my model in my method as a parameter so I have all the data in my model.
I can put the model in a Viewbag to pass it in that works fine. But why can't I pass it in as a parameter instead?
The button I am using is on a modal which is inside of the main view.
[HttpPost]
public ActionResult UnZipDownload(ServiceModel model)
{
if(TempData["ZipName"] != null)
{
bool isValid = false;
string zipName = TempData["ZipName"] as string;
string downloadPath = new KnownFolder(KnownFolderType.Downloads).Path;
string filePath = new KnownFolder(KnownFolderType.Downloads).Path;
downloadPath = Path.GetFullPath(downloadPath);
//Make sure last char on path doesn't allow malicious code outside of it.
if (!downloadPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
downloadPath += Path.DirectorySeparatorChar;
string zipFolder = zipName.Substring(0, zipName.Length - 4);
Directory.CreateDirectory(Path.Combine(downloadPath, zipFolder));
TempData["FolderName"] = zipFolder;
using (ZipArchive archive = ZipFile.OpenRead(filePath + "\\" + zipName)) // downloadPath + zipName
{
filePath += "\\" + zipFolder; // /?/ downloadPath + zipFolder ?? ??
foreach(ZipArchiveEntry entry in archive.Entries)
{
if(entry.FullName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase))
{
string destinationPath = Path.GetFullPath(Path.Combine(filePath, entry.FullName));
entry.ExtractToFile(destinationPath);
}
}
// Unzipped all files into new folder completed
isValid = true;
}
var mod = ViewBag.ServModel;
var servModel = TempData["ServModel"];
if (isValid)
{
ViewBag.AlertSuccess = "The .zip file has been successfully unzipped";
OpenPDFs();
}
}
return RedirectToAction("VirtualService", model);
}
<div id="zipModal" class="modal" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
@using (Html.BeginForm("UnZipDownload", "Service", FormMethod.Post, new { model = Model }))
{
<div class="modal-header text-center">
</div>
<div class="modal-body text-center">
</div>
<div class="modal-footer">
@*Html.ActionLink("OK", "UnZipDownload", "Service", new { @model = Model, @class = "btn btn-success pull-right" })*@
<input type="submit" name="submit" class="btn btn-success pull-right" value="OK"/>
</div>
}
</div>
</div>
</div>