2014-12-04 93 views
0

这里是kendo网格我有<href>标签onclick函数()。现在我想传递文件名作为参数到我的onclick函数。我想通过该文件名到CallAjaxMethod函数作为参数。如何做?如何将参数传递给kendo的javascript函数<a href=""></a>

@(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

首先,参数添加到您的功能,让您可以实际使用的是什么传入:

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")) 
     ) 
) 
相关问题