0

我在单独的对话框中打开的单个剃刀视图上有 2 个表单。表单是使用 jquery post 提交的。

第一种形式完美运行,但第二种形式根本无法识别,当我尝试序列化数据时,它返回一个空字符串。

下面的代码:

@using (Html.BeginForm("SaveElectricReading", "Store", FormMethod.Post, new { id = "frmSaveElectricReading" }))
{
    <div id="electricDialog" style="display: none;" title="Electric Readings">
        <p>
            Please ensure the electric readings have been entered!
        </p>
        <table width="100%">
            <tr>
                <th>
                    Serial:
                </th>
            </tr>
            <tr>
                <td>
                    <input type="text" name="Serial" />
                </td>
            </tr>
            <tr>
                <th>
                    Reading:
                </th>
            </tr>
            <tr>
                <td>
                    <input type="text" name="Reading" />
                </td>
            </tr>
            <tr>
                <th>
                    Comment:
                </th>
            </tr>
            <tr>
                <td>
                    <div class="textwrapper">
                        <textarea rows="5" cols="10" name="Comment"></textarea>
                    </div>
                </td>
            </tr>
        </table>
    </div>
}

@using (Html.BeginForm("SaveWaterReading", "Store", FormMethod.Post, new { id = "myform" }))
{
    <div id="waterDialog" style="display: none;" title="Water Readings">
        <p>
            Please ensure the water readings have been entered!
        </p>
        <table width="100%">
            <tr>
                <th>
                    Serial:
                </th>
            </tr>
            <tr>
                <td>
                    <input type="text" name="WaterSerial" />
                </td>
            </tr>
            <tr>
                <th>
                    Reading:
                </th>
            </tr>
            <tr>
                <td>
                    <input type="text" name="WaterReadingsdfsdf" />
                </td>
            </tr>
            <tr>
                <th>
                    Comment:
                </th>
            </tr>
            <tr>
                <td>
                    <div class="textwrapper">
                        <textarea rows="5" cols="10" name="WaterComment"></textarea>
                    </div>
                </td>
            </tr>
        </table>
    </div>
}

function showWaterDialog() {
    var $dialog = $('#waterDialog').dialog({
        autoOpen: false,
        modal: true,
        width: 400,
        height: 400,
        buttons: {
            Submit: function () {
                //                $('#frmCreateStore').submit();
                var data = $('#frmSaveWaterReading');

                $.post("/Store/SaveWaterReading",
                    $("#frmSaveWaterReading").serialize(),
                    function () {
                        $("#waterDialog").dialog("close");
                    });
                //$(this).dialog("close");
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });

    $dialog.dialog('open');
}
4

1 回答 1

1

在用于显示包含表单的对话框的 jquery 函数中,我需要将该对话框内容添加到页面上的第二个表单中,如下所示:

$("#waterDialog").parent().appendTo($("form").eq(1)[0]);

于 2012-04-05T10:25:50.330 回答