gpt4 book ai didi

jquery - Bootstrap部分 View 模态表单未提交

转载 作者:行者123 更新时间:2023-12-01 05:43:39 24 4
gpt4 key购买 nike

我正在尝试创建一个用于添加的表单。我正在使用 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;
});

请问我提交时错过了什么?

最佳答案

将按钮 type="button"更改为 type="submit"

$('#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;
});
<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>

关于jquery - Bootstrap部分 View 模态表单未提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29078878/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com