Reputation: 2593
I have a Kendo grid with a button on each row, which I want to trigger a URL action to download a PDF file when clicked. In order to do this I need to pass the data ID to the URL action, but I am having a lot of trouble getting a reference to it. This is my table definition:
@(Html.Kendo().Grid(Model.revisions)
.Name("RevisionsGrid")
.Columns(columns =>
{
columns.Bound(p => p.RevisionInfo.RevisionDate).Title("Date Modified");
columns.Bound(p => p.RevisionInfo.User.Name).Title("By User");
columns.Command(command => command.Custom("ViewPdf").Text("View PDF").Click("getPdf"));
})
.Sortable()
.Selectable()
.Events(e => e.Change("selection_change"))
.Pageable(p => p.PageSizes(new[] { 5, 10, 25 }))
.DataSource(dataSource => dataSource
.Server()
.Model(model => model.Id(p => p.RevisionInfo.Id)))
I need a reference to the model's RevisionInfo.Id. I do not want to change this to Ajax binding.
I tried the solution here but this.dataItem
always returns null. I also tried using a reference to the Kendo grid instead of this
with the same result.
function getPdf(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var revisionId= dataItem.RevisionId;
window.location.href = "@Url.Action("GetPdf","Reports")?revisionId=" + revisionId;
}
This seems like it should be simple but I'm at a loss. Any ideas?
Upvotes: 0
Views: 2363
Reputation: 894
You missed the kendo grid element when querying the dataitem:
function getPdf(e) {
e.preventDefault();
var dataItem = $("#RevisionsGrid").data("kendoGrid").dataItem($(e.currentTarget).closest("tr"));
var revisionId= dataItem.RevisionId;
window.location.href = "@Url.Action("GetPdf","Reports")?revisionId=" + revisionId;
}
Good luck!
Upvotes: 1