Hi mahesh213,
You need to move the jQuery Scripts.Render to head section of Layout page.
Check this example. Now please take its reference and correct your code.
Controller
Home
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
ViewBag.Message = "Your application description page.";
return View();
}
public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";
return View();
}
}
KendoForm
public class KendoFormController : Controller
{
// GET: KendoForm
public ActionResult Index()
{
return View();
}
public JsonResult GetCustomers()
{
return Json(Customers(), JsonRequestBehavior.AllowGet);
}
public JsonResult GetCustomerDetails(int id, string name)
{
List<UploadFile> files = UploadFiles().FindAll(x => x.CustomerId == id);
List<FileData> fileData = new List<FileData>();
foreach (UploadFile file in files)
{
fileData.Add(new FileData
{
bytes = System.IO.File.ReadAllBytes(file.FileName),
Name = Path.GetFileName(file.FileName)
});
}
TempData["Data"] = fileData;
return new JsonResult() { Data = new { Name = name } };
}
[HttpGet]
public virtual ActionResult Download(string fileName)
{
if (TempData["Data"] != null)
{
List<FileData> fileData = TempData["Data"] as List<FileData>;
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
foreach (FileData file in fileData)
{
zip.AddEntry(file.Name, file.bytes);
}
string zipName = String.Format("{0}_{1}.zip", fileName, DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
using (MemoryStream memoryStream = new MemoryStream())
{
zip.Save(memoryStream);
return File(memoryStream.ToArray(), "application/zip", zipName);
}
}
}
else
{
return new EmptyResult();
}
}
private List<Customer> Customers()
{
List<Customer> customers = new List<Customer>();
customers.Add(new Customer { CustomerId = 1, Name = "aaaaa" });
customers.Add(new Customer { CustomerId = 2, Name = "bbbbb" });
customers.Add(new Customer { CustomerId = 3, Name = "ccccc" });
return customers;
}
private List<UploadFile> UploadFiles()
{
List<UploadFile> uploadFiles = new List<UploadFile>();
uploadFiles.Add(new UploadFile { UploadId = 1, FileName = "D:/FilePreview/Uplodads/Test.jpg", CustomerId = 1 });
uploadFiles.Add(new UploadFile { UploadId = 2, FileName = "D:/FilePreview/Uplodads/Test.txt", CustomerId = 1 });
uploadFiles.Add(new UploadFile { UploadId = 3, FileName = "D:/FilePreview/Uplodads/Test.pdf", CustomerId = 2 });
return uploadFiles;
}
public class Customer
{
public int CustomerId { get; set; }
public string Name { get; set; }
}
public class UploadFile
{
public int UploadId { get; set; }
public string FileName { get; set; }
public int CustomerId { get; set; }
}
public class FileData
{
public byte[] bytes { get; set; }
public string Name { get; set; }
}
}
Views
KendoForm
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<script type="text/javascript">
var app = angular.module("MyApp", ["kendo.directives"]);
app.controller("MyController", function ($scope, $http, $window) {
$scope.mainGridOptions = {
dataSource: { transport: { read: "/KendoForm/GetCustomers/" }, pageSize: 5 },
pageable: { refresh: true, pageSizes: [2, 25, 50] },
groupable: false,
sortable: true,
columns: [
{ field: "CustomerId", title: "Id", width: 40 },
{ field: "Name", title: "Name", width: 150 },
{
title: "Download Files",
width: '200px',
command: {
text: "Download",
iconClass: "k-icon k-i-download",
click: function (e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
$http({
method: "POST",
url: "/KendoForm/GetCustomerDetails",
params: { id: dataItem.CustomerId, name: dataItem.Name },
headers: { "Content-Type": "application/json" }
}).then(function (response) {
$window.location = '/KendoForm/Download?fileName=' + response.data.Name;
});
}
}
}
]
};
})
</script>
<div ng-app="MyApp" ng-controller="MyController">
<kendo-grid k-options="mainGridOptions" id="tblGrid"></kendo-grid>
</div>
Layout
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2020.1.114/styles/kendo.default-v2.min.css" />
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/angular.min.js"></script>
<script type="text/javascript" src="https://kendo.cdn.telerik.com/2020.1.114/js/kendo.all.min.js"></script>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Home", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
<li>@Html.ActionLink("Kendo", "Index", "KendoForm")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
Screenshot