0

列を表示するグリッドがあり、列の1つにアイコンがあり、クリックすると、クリックしたアイテムのIDに基づいてファイルをダウンロードする必要があります。

アイコンとともにグリッドを表示するためにノックアウトと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>

グリッドの列の 1 つで、私は 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
            });
4

1 に答える 1

1

ビューで次のようなことができます

@{
    string getFileUrl = Url.Action("GetFile");
}

/* in your viewModel, depend how you are doing it, you can do inside your item */ item.getFileUrl = '@getFileUrl' + ?id= this.id;

そしてあなたのhtmlで:

<div data-bind="foreach: item">
    <a data-bind="attr : { href = getFileUrl}">get file</a>
</div>

*注: オブザーバブルは必要ありません *

編集 :

onDataClick: function (row) {
    //Call the method from controller to allow downloading file
    window.open('@getFileUrl' + '?id=' + row.id, "_blank");
},
于 2013-08-23T03:04:29.027 に答える