无法将所选数据从模式中的表行传递到父视图

时间:2017-04-06 00:52:06

标签: c# jquery asp.net-mvc-viewmodel

我有一个复选框,每当我检查它时,都会出现一个模态弹出窗口。

<input type="checkbox" name="inputNewBornKMC" value="inputNewBornKMC" id="inputNewBornKMCCheckbox"> New Born

我在加载模态并在其中执行搜索查询时没有遇到任何问题,但是我有一个问题是将所选数据从模式中的表行传递到父视图。

$('#inputNewBornKMCCheckbox').on('change', function (e) {
        var _this = $(this);

        // if checked
        if (_this.is(':checked')) {
            $('#inputNewBornKMC').modal('show');

        $("#SearchMother").on('click', function () {
                $.ajax({
                    url: '/consultation/GetMothersDetailList',
                    type: 'GET',
                    data: $('#frmSearchMother').serialize(), // it will serialize the form data
                    dataType: 'json',
                    success: function (data) {
                        $('.firstDL').remove(); 
                        $('.subsequentPL').remove();

                        var rowNo = 0;
                        for (var i = 0; i < data.length; i++) {
                            rowNo += 1;
                            $("#LoadMotherDetailsTable tbody").append("<tr Class='odd gradeX subsequentPL'>" +
                                        "<td>" + rowNo + "</td>" +
                                        "<td>" + data[i].paid + "</td>" +
                                        "<td>" + data[i].pidno + "</td>" +
                                        "<td>" + data[i].pname + "</td>" +
                                        "<td><button type='button' class='select btn btn-default' data-paid='" + data[i].paid + "'>Select</button></td>" +
                            "</tr>");
                        }

                        alert('LoadMotherDetailsTable list has been loaded.');

                    },
                    error: function () {
                        alert('Ajax Submit Failed ...');
                    }
                }); // end ajax

            });

            var baseUrl = '@Url.Action("GetMotherDetails", "consultation")';
            $("#LoadMotherDetailsTable tbody").on('click', '.select', function () {

                $.getJSON(baseUrl, { paid: $(this).data('paid') }, function (data) {

                    document.getElementById('#inputMotherMRN').style.display = 'block';
                    document.getElementById('#inputMotherMRNlabel').style.display = 'block';
                    $('#inputMotherMRN').val(data.paid);
                    $('#inputMotherName').val(data.pname);
                    $('#inputNewBornKMC').modal('hide');

                });
            });
}

据说,在我点击表格行中的选择按钮后,模式将隐藏,将出现标签和文本框,相关数据将显示在父页面的标签和文本框中。

但是模式不会关闭,文本框和标签不会出现,数据也不会传递。为什么会这样?有人可以借给我一只手吗?

更新

$.getJSON(baseUrl, { paid: $(this).data('paid') }, function (data) {

                    $('#inputMotherMRN').val(data.paid);
                    $('#inputMotherName').val(data.pname);                        
                });

document.getElementById('#inputMotherMRN').style.display = 'block';
document.getElementById('#inputMotherMRNlabel').style.display = 'block';
$('#inputNewBornKMC').modal('hide');

传递数据但模态不会关闭,隐藏的文本框和标签也不会出现。当我检查调试器控制台时,即使移动了行,问题似乎仍然是document.getElementById('#inputMotherMRN').style.display = 'block';特定行。

这是隐藏的文本框和标签:

<label for="inputMotherMRN" class="col-sm-3 control-label" id="inputMotherMRNlabel" style="display:none">Mother's MRN</label>
<div class="col-sm-9">
     <input type="text" class="form-control input-sm" id="inputMotherMRN" name="inputMotherMRN" style="display:none" readonly>
</div>

0 个答案:

没有答案