将数据从jQueryUI对话框表单传递给控制器

时间:2017-03-28 10:10:26

标签: javascript jquery asp.net asp.net-mvc jquery-ui

我是ASP.NET / Javascript的新手,我在使用jQueryUI对话框表单实现简单的CRUD操作时遇到了一些麻烦。这是我的代码:

<button class="update" id="@Model.id">Update</button>
<div id="dialog-form" title="Update">
  <form>
    <fieldset>
      <input type="text" name="state" id="state">
      <input type="text" name="note" id="note">
      <input type="submit">
    </fieldset>
  </form>
</div>

<script>
      $(function() {
          var dialog,
            state = $("#state"),
            note = $("#note"),
            id = this.id, //??
            dialog = $("#dialog-form").dialog({
              autoOpen: false,
              height: 400,
              width: 350,
              modal: true,
              buttons: {
                "Ok": function() {
                  $.ajax({
                    type: "POST",
                    url: "@Url.Action("Update","Ticket")",
                    data: {
                      id: id,
                      state: state,
                      note: note
                    },
                    cache: false,
                    dataType: "json",
                    success: function(data) {
                      $("#dialog").dialog("close");
                    }
                  });
                },
                "Cancel": function() {
                  $(this).dialog("close");
                }
              }
            });

          $(".update").button().on("click", function() {
            dialog.dialog("open");
          });
        });
</script>    

最后Update中的TicketController操作:

  public ActionResult Update(String id, String state, String note)
    {
        //do some stuff
    }

然而,没有任何事情发生,也没有进入行动。非常感谢任何帮助

1 个答案:

答案 0 :(得分:2)

使用{{3}}

更改您的SELECT COUNT(*) "EVENTS", TRUNC( TIMESTAMP '1970-01-01 00:00:00.000' + NUMTODSINTERVAL( MSSTAMP / 1000, 'SECOND' ), 'MM' ) "FINISHED_MONTH" FROM DB_TABLE WHERE MSSTAMP < 1483228800000 AND STATUS = 'FINISHED' GROUP BY TRUNC( TIMESTAMP '1970-01-01 00:00:00.000' + NUMTODSINTERVAL( MSSTAMP / 1000, 'SECOND' ), 'MM' ); ,如下所示,您需要传递值而不是对象
data

使用state = $("#state").val(), note = $("#note").val(), id = "Pass anything you wants" data: { 'id':id,'state':state,'note':note },

装饰您的操作方法
[HttpPost]