How to pass a jQuery object as a parameter into jqGrid using the lib.web.mvc namespace

谁说我不能喝 提交于 2020-01-03 05:23:18

问题


This is my first time with really trying to set up jqGrid with Lib.Web.MVC. Once I'm able to get the initial setup done, I should be able to roll along more smoothly.

I've downloaded the chm file for the Lib.Web.Mvc helper and looked under the JqGridHelper, but can't find anything on how to do the above subject line. I've also searched the web, but can't find anything specific on what I need to do.

I need to pass an object into my method as an input parameter but don't know how to set that up with Lib.Web.Mvc.

In jQuery, to set up the object, I was doing the following which passed in the object just fine.

var HH_FuelTkt_Input = {
                                Vehicle_No: $('#txtVehicleNbr').val(),
                                Customer_Name: $('#txtCustomerName').val(),
                                Trans_Timestamp_Begin: $('#dteBeginDate').val(),
                                Trans_Timestamp_End: $('#dteEndDate').val()
                            };
                            $.ajax({
                                url: '@Url.Action("GetFilteredFuelTicketsAsync")',
                                data: JSON.stringify(HH_FuelTkt_Input),   

How can I accomplish this same thing using the lib.web.mvc namespace? Here is my code for that. Note that the line "JqGridParametersNames.HH_FuelTkt_Input" says that there is no definition for "HH_FuelTkt_Input". This makes sense, because the Helper can't find that object. How can I make the helper aware of that jQuery object?

<table id="fuelTickets" class="table">
                  @{
                    var grid = new JqGridHelper<FuelTktImgRetrievalMdl.ViewModels.HH_FuelTkt_Output>("FuelTickets",
                      dataType: JqGridDataTypes.Json,
                      methodType: JqGridMethodTypes.Post,
                      pager: true,
                      rowsNumber: 10,
                      sortingName: "FuelTkt_ID",
                      sortingOrder: JqGridSortingOrders.Asc,
                      viewRecords: true,
                      autoWidth: true,
                      gridView: true,
                      JqGridParametersNames.HH_FuelTkt_Input,
                      url: Url.Action("GetFilteredFuelTicketsAsync"),
                      caption: "Fuel Tickets",
                      onCellSelect: "getImageId",
                      emptyRecords: "No records to view"
                    );
                }
            </table>

回答1:


You can achieve this with PostDataScript property, something like this:

@{
    var grid = new JqGridHelper<FuelTktImgRetrievalMdl.ViewModels.HH_FuelTkt_Output>("FuelTickets",
        dataType: JqGridDataTypes.Json,
        methodType: JqGridMethodTypes.Post,
        pager: true,
        rowsNumber: 10,
        sortingName: "FuelTkt_ID",
        sortingOrder: JqGridSortingOrders.Asc,
        viewRecords: true,
        autoWidth: true,
        gridView: true,
        JqGridParametersNames.HH_FuelTkt_Input,
        url: Url.Action("GetFilteredFuelTicketsAsync"),
        caption: "Fuel Tickets",
        onCellSelect: "getImageId",
        emptyRecords: "No records to view",
        postDataScript: "function() { return { Vehicle_No: $('#txtVehicleNbr').val(), Customer_Name: $('#txtCustomerName').val(), Trans_Timestamp_Begin: $('#dteBeginDate').val(), Trans_Timestamp_End: $('#dteEndDate').val() }; }"
    );
}

The object will be available to your action method in standard way (for example you can create an entity for it and make that entity another parameter of your action).



来源:https://stackoverflow.com/questions/23477551/how-to-pass-a-jquery-object-as-a-parameter-into-jqgrid-using-the-lib-web-mvc-nam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!