这是kendo网格我有<href>
标签和onclick函数()。现在我想将filename作为参数传递给我的onclick函数。我想将该文件名作为参数传递给CallAjaxMethod函数。怎么办?
@(Html.Kendo().Grid<MVCAPPModels..AttachmentsModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.FileName).ClientTemplate("<a id='FileName' href='\\#' data-pdfurl='#= FileName #' onclick='CallAjaxMethod('#= FileName #');'>/#= FileName #</a>");
columns.Bound(c => c.CreatedDate).Width(70);
columns.Bound(c => c.CreatedBy).Width(70);
columns.Bound(c => c.UpdatedDate).Width(70);
columns.Bound(c => c.UpdatedbBy).Width(70);
})
.HtmlAttributes(new { style = "height: 350px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(1))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Read(read => read.Action("Customers_Read", "Home"))
)
)
JavaScript函数:
function CallAjaxMethod()
{
alert("page! CallAjax");
$.ajax({
type: "POST",
url: "@Url.Action("Submit", "Home")",
data: { fileName: "/pdfSample.pdf" },
type: 'GET',
cache: false,
success: function (result) {
$('#partialView_div').data(result);
}
});
}
答案 0 :(得分:0)
首先,在函数中添加一个参数,这样就可以实际使用传入的内容:
function CallAjaxMethod(filename)
{
alert("page! CallAjax");
$.ajax({
type: "POST",
url: "@Url.Action("Submit", "Home")",
data: { fileName: filename },
type: 'GET',
cache: false,
success: function (result) {
$('#partialView_div').data(result);
}
});
}
然后您的HTML和Javascript引用相互冲突,因为它们都是单引号,因此您需要更改其中一些,最好是HTML:
@(Html.Kendo().Grid<MVCAPPModels.AttachmentsModel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(p => p.FileName).ClientTemplate("<a id=\"FileName\" href=\"\\#\" data-pdfurl=\"#= FileName #\" onclick=\"CallAjaxMethod('#= FileName #');\">/#= FileName #</a>");
columns.Bound(c => c.CreatedDate).Width(70);
columns.Bound(c => c.CreatedBy).Width(70);
columns.Bound(c => c.UpdatedDate).Width(70);
columns.Bound(c => c.UpdatedbBy).Width(70);
})
.HtmlAttributes(new { style = "height: 350px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(1))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Read(read => read.Action("Customers_Read", "Home"))
)
)