jquery - 从 jQuery Grid 插件将额外参数传递给 ASP.NET MVC Controller 操作

标签 jquery asp.net-mvc asp.net-mvc-3 jqgrid

我正在尝试使用 jQuery Grid 插件和 ASP.NET MVC 来显示数据。网络上提供的示例似乎表明 Controller 操作签名如下所示:

public ActionResult SomeMethod(string sidx, string sord, int page, int rows) { }

有什么方法可以从页面上的各个输入字段传递额外的参数吗?

干杯, D.

添加:我还没有编写任何代码,但客户端代码将类似于:

jQuery(document).ready(function(){ 
      jQuery("#list").jqGrid({
        url:'/Entry/GridData/',
        datatype: 'json',
        mtype: 'POST',
        colNames:['Entry Date','Registration','Registered Name'],
        colModel :[
          {name:'EntryDate', index:'EntryDate', width:40 },
          {name:'Registration', index:'Registration', width:200 },
          {name:'RegisteredName', index:'RegisteredName', width:200 }],
        pager: jQuery('#pager'),
        rowNum:20,
        rowList:[5,10,20,50],
        altRows: true,
        sortable: false,
        viewrecords: true,
        caption: 'My first grid'
      }); 
    });

服务器端代码如下:

public ActionResult GridData(string sidx, string sord, int page, int rows)
{
    //Some stuff to get data, which needs a couple of extra parameters on top of the ones in the signature
    return Json(dataCollection);
}

在 GridData 操作中,我需要更多参数来获取适当的数据。如何在 javascript 中指定这些,以及如何在 Controller 操作中获取它们?

最佳答案

您可以使用 postData 属性:

$('#list').jqGrid({
    url: '@Url.Action("SomeMethod")',
    datatype: 'json',
    mtype: 'POST'
    postData: { 
        someParam1: $('#someInput1').val(),
        someParam2: $('#someInput2').val() 
    }
    ...
});

并且在您的 Controller 操作中您可以添加此参数:

public ActionResult SomeMethod(string someParam1, string someParam2, string sidx, ...) { }

关于jquery - 从 jQuery Grid 插件将额外参数传递给 ASP.NET MVC Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4983169/

相关文章:

javascript - 通过 ajax 通过一个按钮将单个表单提交给两个操作

c# - 使用默认链接的 web api 版本控制

asp.net表单例份验证多人使用同一用户名登录

asp.net-mvc-3 - ASP.NET MVC 3 不接受我的德语日期格式设置 - 为什么?

Javascript回调函数——疑惑与误解

asp.net - 如何使用 J 查询使只读文本框在鼠标悬停时可编辑

javascript - 从javascript中的字符串中提取 float

asp.net-mvc - 路由、命中错误 Action

c# - asp.net 5 中的国际化

c# - 使用 JSON.Net 序列化包含撇号的字符串