从JqGrid检索已编辑的数据并在Web Api中使用它

时间:2016-01-22 13:27:31

标签: jqgrid httprequest

说我有form.我要编辑一行并提交。 我有PUT代码:

$("#jqgrid").jqGrid('navGrid', pagerSelector,
                {
                    //navbar options
                    edit: true,
                    editicon: 'ace-icon fa fa-pencil blue',
                    add: true,
                    addicon: 'ace-icon fa fa-plus-circle purple',
                    del: true,
                    delicon: 'ace-icon fa fa-trash-o red',
                    search: true,
                    searchicon: 'ace-icon fa fa-search orange',
                    refresh: true,
                    refreshicon: 'ace-icon fa fa-refresh green',
                    view: true,
                    viewicon: 'ace-icon fa fa-search-plus grey'
                },
                {
                    recreateForm: true,
                    mtype: 'PUT',
                    onclickSubmit: function (params, postdata) {
                        params.url = API_URL + 'Update';
                    },
                    beforeShowForm: function (e) {
                        var form = $(e[0]);
                        form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />');
                        styleEditForm(form);
                    }
                },

我的问题是如何在我的Asp.net Web Api中检索数据?

    // UPDATE
    [Microsoft.AspNet.Mvc.HttpPut]
    public void Update()
    {
        try
        {
            var item = GetEditedRowDataFromJqGrid(); // how to get item?
            _respository.Update(item);
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.Message);
        }
    }

1 个答案:

答案 0 :(得分:0)

找到答案:

 // UPDATE
    [Microsoft.AspNet.Mvc.HttpPut("{id}")]
    public void UpdateVendor(string id)
    {
        try
        {
            var item = new Vendor()
            {
                Company = Request.Form["Company"],
                UserName = Request.Form["UserName"]
            };
            _vendorRespository.UpdateVendor(item);
        }
        catch (Exception e)
        {
            Debug.WriteLine(e.Message);
        }
    }