如何从JQGrid获取行单元格值到Controller Action方法 [英] How to get an rows cell value from JQGrid to Controller Action method

查看:237
本文介绍了如何从JQGrid获取行单元格值到Controller Action方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii to all,

我要求我需要从DataBase&获取两个表数据。在JQGrid中显示,我使用EntityFramework& LINQ in MVC3,这里我还有一个要求,即iam面临问题,除了表数据我需要再显示一个ActionLinks列,每当用户点击ActionLink时,我需要各自的列ID(即各行单元数据)进入控制器。这是我尝试编写我的JQGrid代码以满足我的要求。

Hii to all,
I have a requirement that i need to get an two tables data from DataBase & display in JQGrid,i have done this using EntityFramework & LINQ in MVC3,here i have one more requirement that where iam facing problem,in addition to the table data i need to display one more column with ActionLinks,whenever user click on ActionLink the respective columns ID(i.e respective rows cell data) i need to get in the controller.This is how i tried by writing my JQGrid code to meet my requirement.

$("#emp-data-grid").jqGrid({
        datatype: "local",
        data: mdata,
        colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email", ""],
        colModel: [
                { name: "EmployeeID", index: "EmployeeID", sortable: false,
                    editable: true, edittype: 'checkbox', editoptions: { value: 'true:false' }
                },
                { name: "EmpName", index: "EmpName" },
                { name: "Designation", index: "Designation" },
                { name: "Salary", index: "Salary", sorttype: "int" },
                { name: "MobileNo", index: "MobileNo", sorttype: "int" },
                { name: "Email", index: "Email" },



{name:'Link',formatter:function(cellvalue,options,rowObject){


{name: 'Link', formatter: function (cellvalue, options, rowObject) {

var x = '@Html.ActionLink("EDIT", "Edit", "Home", new { EmployeeID = "id" }, new { @style = "color:Blue;font-weight:bold;" })';
                    return x.replace("id", rowObject[1]);
                }, align: 'left', width: 100,editurl: ' / Home / Edit / '
            }
            ],

        shrinkToFit: true,
        viewrecords: true,
        sortorder: 'asc'
      caption: "Employee List"
    });
This is my Controller Code:-
 public ActionResult Edit(int? id)
{
 return view();
}
In the above controller i want to access id and send to view for displaying that id in some textbox,using viewdata. Please guide me where iam doing mistake,...
 Thanks
 Ramu

推荐答案

#emp-data-grid)。jqGrid( {
datatype: local
data:mdata,
colNames:[ EmployeeID EmpName 名称 薪水 MobileNo 电子邮件 ],
colModel:[
{name: EmployeeID,index: EmployeeID,sortable: false
editable: true ,edittype:' 复选框',editoptions:{ value ' true:false'}
},
{name: EmpName,index: EmpName},
{name: 名称,索引: 名称},
{name: 薪水,索引: 薪水, sorttype: int},
{name: MobileNo,index: MobileNo,sorttype: int},
{name: 电子邮件,索引: < span class =code-string> Email},
("#emp-data-grid").jqGrid({ datatype: "local", data: mdata, colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email", ""], colModel: [ { name: "EmployeeID", index: "EmployeeID", sortable: false, editable: true, edittype: 'checkbox', editoptions: { value: 'true:false' } }, { name: "EmpName", index: "EmpName" }, { name: "Designation", index: "Designation" }, { name: "Salary", index: "Salary", sorttype: "int" }, { name: "MobileNo", index: "MobileNo", sorttype: "int" }, { name: "Email", index: "Email" },



{name:'Link',formatter:function(cellvalue,options,rowObject){


{name: 'Link', formatter: function (cellvalue, options, rowObject) {

var x = '@Html.ActionLink("EDIT", "Edit", "Home", new { EmployeeID = "id" }, new { @style = "color:Blue;font-weight:bold;" })';
                    return x.replace("id", rowObject[1]);
                }, align: 'left', width: 100,editurl: ' / Home / Edit / '
            }
            ],

        shrinkToFit: true,
        viewrecords: true,
        sortorder: 'asc'
      caption: "Employee List"
    });
This is my Controller Code:-
 public ActionResult Edit(int? id)
{
 return view();
}
In the above controller i want to access id and send to view for displaying that id in some textbox,using viewdata. Please guide me where iam doing mistake,...
 Thanks
 Ramu


在下面的电子邮件之后添加一个新的隐藏列,并将rowobject索引更改为rowObject [6]

Add a new hidden column after email like below and change rowobject index to rowObject[6]
colNames: ["EmployeeID", "EmpName", "Designation", "Salary", "MobileNo", "Email","EmployeeId", ""],


 { name: 'EmployeeID', index: 'EmployeeID', width: 1, align: 'left',hidden:true },





我认为你将布尔值绑定到第一个EmployeeId列。这就是为什么你有空值。



希望这有帮助



I think you are binding boolean value to your first EmployeeId column. That's why you got null value.

Hope this helps


这篇关于如何从JQGrid获取行单元格值到Controller Action方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆