我有一個網格,其中我顯示列和其中一列有一個圖標,一旦點擊它應該下載一個文件的基礎上點擊項目的ID。連接控制器,以淘汰js
因爲我使用基諾和jQuery的JavaScript來顯示網格與圖標一起。我怎樣才能將文件的方法連接到我的js文件中的圖標?
JS文件:
onDataClick: function (row) {
//Call the method from controller to allow downloading file
},
控制器 - 獲得方法:
public FileResult GetFile(int id)
{
.....
}
更新
查看:
@{
ViewBag.Title = "Some Title";
string url = Url.Action("GetFile");
}
<div data-bind="template: { name: 'knockoutGridTemplate', data: grid }" class="gridWrapper"></div>
在網格中的列我在js文件之一:
builtColumns.push({
property: 'hasStuff',
header: 'File Download',
dataCss: 'iconHolder',
onDataClick: function (row) {
},
dataFormatter: function (row) {
if (row[this.property]) return ' ';
return '';
},
dataLinkCss: 'icon-file',
grouping: 3
});
看起來你也許可以用一個iframe和一個自定義KnockoutJS結合在詳細的做到這一點[通過在ASP.NET MVC中發佈JSON數據下載CSV文件]的接受答案(http://stackoverflow.com/questions/18114322/download-csv-file-by-posting-json-data-in-asp-net- MVC)。 –