MVC从TextBoxFor填充Textboxfor值onbuttonclick

时间:2018-06-18 06:30:02

标签: javascript asp.net-mvc

我对此有点新意。如何使用按钮上的TextBoxFor填充TextBoxFor的值? 我正在创建一个确认模式,其中用户在TextBoxFor中输入数据,当单击提交按钮时,将弹出一个确认对话框并提交他的凭据。问题是模态TextBoxFor

中没有显示任何值

父TextBoxFor

<div class="col-md-10">
        @Html.TextBoxFor(model => model.name, new { htmlAttributes = new { @class = "form-control", @id = "name" } })
        @Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
<button type="button" id="submitBtn" class="btn btn-primary" data-toggle="modal" data-target="#login-modal" data-backdrop="static" data-keyboard="false">Submit</button>

模态TextBoxFor

<div id="login-modal" tabindex="-1" role="dialog" aria-hidden="true" class="modal fade">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            Confirm Submit
            <button type="button" data-dismiss="modal" aria-hidden="true" class="close">×</button>
        </div>
        <div class="modal-body">
            Are you sure you want to submit the following details?
            <br/>
            <br/>

                <table class="table">
                    <tr>
                        <th>Queue Number</th>
                        <td>@Html.TextBoxFor(model => model.name, new {htmlAttributes = new {@class = "form-control", @id = "namee"}})</td>
                    </tr>
                </table>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <a href="#" id="submit" class="btn btn-success success">Submit</a>
        </div>
            }
    </div>
</div>

脚本

    $('#submitBtn').click(function () {
        $('#namee').text($('#name').val());

        var x = document.getElementById("name").value;
        document.getElementById("namee").innerHTML = x;
    });

我还尝试使用<input type>更改父TextBoxFor,但仍然无所事事。

提前致谢。

0 个答案:

没有答案