简体   繁体   English

单击按钮时如何从jqgrid的弹出窗口传递?

[英]How to pass from pop up of jqgrid when clicked button?

I use mvc4. 我用的是mvc4。 There is button in rows of jqgrid. jqgrid的行中有按钮。 when clicked button, open pop up and in pop up edit data of row's grid. 单击按钮后,打开弹出窗口,并在弹出窗口中编辑行网格的数据。 but when clicked button of pop up don't pass data to action of controller. 但是当单击弹出按钮时,不会将数据传递到控制器的动作。 code of pop up: 弹出代码:

{
     name: 'Notes',
     width: 160,
     sortable: false,
     resizable: false,
     search: false,
     formatter: function () {
         return "<button onclick='OpenDialog()' style='margin-left:12px'>Pop Up Dlg</button>";
     }
 }

code of pop up ( http://jqueryui.com/dialog/#modal-form ): 弹出代码( http://jqueryui.com/dialog/#modal-form ):

<script>
    $(function() {
        var dialog, form,
        modserial = $("#ModSerial"),
            simno = $("#SimNo"),

            function addUser() {
                $(function() {
                    $.ajax({
                        url: '@Url.Action("EditMet", "MetGrid")',
                        data: "{'ModSerial':'" + document.getElementById('ModSerial').value + "', 'SimNo':'" + document.getElementById('SimNo').value + "'}",
                        type: "Post",
                        dataType: "Html",
                        success: function(result) {
                            $("#Data").html(result);
                        },
                        error: function() {
                            alert("Error!");
                        }
                    });
                });
            }

            function log() {}
        dialog = $("#dialog-form").dialog({
            autoOpen: false,
            height: 400,
            width: 350,
            modal: true,
            buttons: {
                "...": log,
                    "Confirm": addUser,
                Cancel: function() {
                    dialog.dialog("close");
                }
            },
            close: function() {
                form[0].reset();
                allFields.removeClass("ui-state-error");
            }
        });
        form = dialog.find("form").on("submit", function(event) {
            event.preventDefault();
            addUser();
        });
    });
</script>

When call action(@Url.Action("EditMeter", "MeterGrid")), pass null to controller. 调用action(@ Url.Action(“ EditMeter”,“ MeterGrid”))时,请将null传递给控制器​​。 How to pass data and id's row grid to action? 如何将数据和ID的行网格传递给行动?

You should use contentType: "application/json;charset=utf-8" and stringify the JSON data like follwoing. 您应该使用contentType: "application/json;charset=utf-8"并对JSON数据进行stringify ,如follwoing。

$.ajax({
     url: '@Url.Action("EditMet", "MetGrid")',
     data: JSON.stringify({"ModSerial": document.getElementById('ModSerial').value, "SimNo": document.getElementById('SimNo').value}),
     type: "post",
     contentType: "application/json;charset=utf-8",
     dataType: "Html",
     success: function(result) {
               $("#Data").html(result);
     },
     error: function() {
               alert("Error!");
     }
 });

Hope it will work now. 希望它现在可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM