【问题标题】:In 3 level JqGrid, get the first table's primary key when the 2nd table's "+" sign is pressed在 3 级 JqGrid 中,按下第二个表的“+”号时获取第一个表的主键
【发布时间】:2014-12-03 17:25:56
【问题描述】:

我是 JqGrid 的新手,请帮我解决这个请求。

我有一个 3 级分层 JqGrid 设置,如 link 所示。它不完全相同,但非常相似。我的要求是在扩展OrderGrid 时也传递CustomerGrid 的主键。

或者简而言之,我想拥有

    public void SetUpThreeLevelGrids(ThreeLevelHierarchyJqGridModel model)
    {
        var customersGrid = model.CustomersGrid;

        // code here

        int cId;
        //cId = <CustomerId from the CustomerGrid>; //*****How to get this******
        ordersGrid.DataUrl = Url.Action("ThreeLevel_OrdersDataRequested", new { customerId =  cId });

        // code here
    }

我想使用传递给ThreeLevel_OrderDetailsDataRequested 方法的变量:

public JsonResult ThreeLevel_OrderDetailsDataRequested(int customerId, string parentRowID)
{
    // code here
}

【问题讨论】:

  • 投反对票?我可以知道为什么吗?

标签: c# visual-studio-2010 asp.net-mvc-4 mvcjqgrid


【解决方案1】:

我在控制器中创建了一个名为 CustomerId 的静态变量。我不知道这是否会破坏任何东西。我只是想让它工作。

public static int customerId = 0;

在第二个网格的 Action 方法中,我分配了 CustomerId 值。

public JsonResult ThreeLevel_OrdersDataRequested(string parentRowID)
{
    var northWindModel = new NorthwindDataContext();
    var model = new ThreeLevelHierarchyJqGridModel();
    customerId = int.Parse(parentRowID);
    SetUpThreeLevelGrids(model);

    //code
}

访问了第三级网格中的全局静态变量。

public JsonResult ThreeLevel_OrderDetailsDataRequested(string parentRowID)
{    
    //Code
    var orderDetails = from o in myDbModel.MyCustomerOrderDetails
         where o.OrderID == Convert.ToInt32(parentRowID)
         and o.CustomerId == customerId //static global variable
         select o;

    //Code
}

如果有人对在第三级网格中获取第一级表的选定主键有更好的建议,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-05
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多