Bootstrap部分视图模式表单不提交

时间:2015-03-16 14:08:04

标签: jquery asp.net-mvc twitter-bootstrap bootstrap-modal

我正在尝试创建一个表单来添加。我正在使用bootstrap模态窗口来获取数据 这是我的部分观点

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">Register Datasource</h4>
        </div>
        <div class="modal-body">
            @using (Html.BeginForm("Add", "DataSource", FormMethod.Post, new { id = "order-form", @class = "smart-form", novalidate = "novalidate" }))
            {
                <!-- modal data -->
            }
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">
                Cancel
            </button>
            <button type="button" class="btn btn-primary">
                Add
            </button>
        </div>
    </div><!-- /.modal-content -->
</div>
索引页面上的

我点击按钮点击模式显示

$('#btn-addDataSource').on('click', function() {
                var url = '@Url.Action("AddProvider","DataSource")';
                $.get(url, function (data) {
                    $('#register-modal').html(data).modal('show');
                });
            });

但是当我提交表格时,它不提交我使用

$('#register-modal form').submit(function () {
    $.ajax({
        url: this.action,   
        type: this.method,
        data: $(this).serialize(),
        success: function (result) {
            if (result.success) {
                $('#register-modal').modal('hide');

            }
        }
    });
    return false;
});

我在提交时错过了什么?

2 个答案:

答案 0 :(得分:1)

而不是按钮类型=&#34;按钮&#34;改为type =&#34;提交&#34;

&#13;
&#13;
$('#order-form').submit(function () {
    $.ajax({
        url: this.action,   
        type: this.method,
        data: $(this).serialize(),
        success: function (result) {
            if (result.success) {
                $('#register-modal').modal('hide');

            }
        }
    });
    return false;
});
&#13;
<div class="modal-dialog">
    <div class="modal-content">
       @using (Html.BeginForm("Add", "DataSource", FormMethod.Post, new { id = "order-form", @class = "smart-form", novalidate = "novalidate" }))
            {
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">Register Datasource</h4>
        </div>
        <div class="modal-body">
           
            
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">
                Cancel
            </button>
            <button type="submit" class="btn btn-primary">
                Add
            </button>
        </div>
          <!-- modal data -->
            }
    </div><!-- /.modal-content -->
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

它是一个黑客,但尝试通过j查询提交它。即:

$(document).on("click", "#btnEdit", function(){
    $("#formEditCustomer").submit();
});