Ajax +webapi 传值问题 修改已获取到了数据,怎么通过提交Onclick 把Id传到Update里呢

时间:2022-08-17 19:01:56
表单,用webapi提交 修改的数据时需要传Id http://localhost:11681/api/User/PutUser/"+Id
已经在前台获取到Id的值 ,怎么传入别的函数—————— Update(Id)
<!--修改弹出框-->
    <div class="modal fade" id="Update" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
                </div>
                <div class="modal-body">
                    <form id="defaultForm" method="post" class="form-horizontal">

                        <div class="form-group">
                            <label class="col-lg-3 control-label" for="UserNo">编号</label>
                            <div class="col-lg-6">
                                <input type="text" readonly class="form-control" name="UserNo" required id="UserNo" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label" for="UserName">用户名</label>
                            <div class="col-lg-6">
                                <input type="text" class="form-control" name="UserName" required id="UserName" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label" for="Account">账号</label>
                            <div class="col-lg-6">
                                <input type="text" class="form-control" name="Account" required id="Account" />
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-3 control-label" for="Password">密码</label>
                            <div class="col-lg-6">
                                <input type="password" class="form-control" name="Pssword" required id="Password" />
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="Update('Id')">保存</button>
                </div>
            </div>
        </div>
    </div>

JS代码:
  $("#btn_edit").click(function () {
            // var row = $("#list").jqGrid('getRowData', Id);
            //获取多选到的id集合
            var ids = $("#list").jqGrid("getGridParam", "selarrrow");
            //遍历访问这个集合
            $(ids).each(function (index, Id) {、
                //由id获得对应数据行
                var row = $("#list").jqGrid('getRowData', Id);
                var Id = row.UserNo;// 已获取
                $("#UserNo").val(row.UserNo);
                $("#UserName").val(row.UserName);
              var CreateTime=row.CreateTime;
                $("#Account").val(row.Account);
                $("#Password").val(row.Password);
                $("#Update").val(row.Update);
            });
            
            });
        function Update(Id) {
            //获取模态框数据
            var userno = $('#UserNo').val();
            var username = $("#UserName").val();
            var account = $("#Account").val();
            var password = $("#Password").val();
            var myDate = new Date();
            var update = myDate.toLocaleDateString();
            alert(Id);
            var user = { UserNo: userno, UserName: username, Password: password, Account: account, Update: update, Create: 2014 / 09 / 01 }
           
            $.ajax({
                type: "Put",
                url: "http://localhost:11681/api/User/PutUser/"+Id,
                datatype: "json",
                contentType: "application/json;charset=utf-8",
                success: function (result) {
                    alert("修改成功!");
                    location.reload();
                }
            });
        }

1 个解决方案

#1


已解决·!!!!

#1


已解决·!!!!