gpt4 book ai didi

jquery - 为什么数据没有传递到 JQuery 中的 Controller

转载 作者:行者123 更新时间:2023-12-01 00:32:13 24 4
gpt4 key购买 nike

我在 MVC2 中有一个页面,其中包含网格和图像按钮。单击图像按钮时,currentPage、orderBy 和过滤器将被发布到 JQuery 中的 Controller 。代码是,

<script type="text/javascript">
$("#ExportExcel").click(function (e) {
e.preventDefault();

var resourceId = $('#resourceId').val();
var grid = $('#Grid').data('tGrid');
var pagenum = grid.currentPage;
var orderBy = grid.orderBy
var filter = grid.filterBy;

$.ajax({
url: '@Url.Action("ExportToExcel", "ExportExcelButton")',
data: { resourceId: resourceId, pagenum: pagenum, orderBy: orderBy, filter: filter },
type: 'POST',
success: function (data) {
}
});
});
</script>

<a href="<%: Url.Action("ExportToExcel", "ExportExcelButton") %>"> <img src='<%: Url.Content("~/Content/Images/ExportExcelButton.gif") %>'/></a>

public ActionResult ExportToExcel(string resourceId, string pagenum, string orderBy, string filter)

但是,当单击图像按钮时,ExportToExcel 操作中的所有数据均为空。我想知道正确的方法是什么。多谢。

最佳答案

我在您的代码中发现两个问题:

  1. 在 html 中,您没有指定链接的 id,因此单击它只是导航到操作,这就是您在参数中看到 null 的原因 - 没有发送
    应该是:

    <a id="ExportExcel" href="<%: Url.Action("ExportToExcel", "ExportExcelButton") %>"> <img src='<%: Url.Content("~/Content/Images/ExportExcelButton.gif") %>'/></a>
  2. 将脚本标签放在链接减速下方或$(document).ready(..)期间绑定(bind)

关于jquery - 为什么数据没有传递到 JQuery 中的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11535431/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com