我有一个带工具栏的kendo网格。我添加了一个从工具栏下载的链接,现在问题是我无法调用Javascript函数,该函数通过数据传递给控制器。
如何在Url.Action上调用java脚本函数?
工具栏
.ToolBar(toolBar => toolBar.Template("<a onclick='getData()' href ='" + Url.Action("", "", null, "https") + "?SeletectOrders=#= SeletectOrders#'" + ">Download Selected Orders</a>"))
如果我输入控制器名称和功能,它会将空数据传递给控制器并下载显示在浏览器底部的空文件。我真的不确定我是否正确这样做
转到控制器的Javascript函数
function getData(SeletectOrders)
{
$.ajax({
url: '@Url.Action("myAction", "mycontroller")',
type: "GET",
contentType: 'application/json; charset=utf-8',
dataType: "text",
data: { SeletectOrders: SeletectOrders },
traditional: true,
async: false,
cache: false,
complete: function (data) {
},
error: function () {
}
})
}
控制器
[HttpGet]
public virtual ActionResult myAction(string[] SeletectOrders)
{
List<string> ListPossDetails = new List<string>();
if (SeletectOrders != null)
{
string[] OrderArray = SeletectOrders;
foreach (var list in OrderArray)
{
ListPossDetails.Add(list);
}
}
//download methods here
Response.AppendHeader("Content-Disposition", "attachment; filename=" + possFilename);
ListPossDetails = null;
return File(fileBytes, type, possFilename);
}