AngularJS模态关闭,带有进入表单的按钮,导致重定向 [英] AngularJS Modal Closing, with button into Form, cause redirect
问题描述
我通过angularjs模态打开了一页(.aspsx),这是代码:
i have one page (.aspsx) open by angularjs modal, this is the code:
<form id="form1" class="form-horizontal" runat="server">
<div class="modal-header">
<div style="float: left; display: block;">
<h3 class="modal-title">{{vmc.title}}</h3>
</div>
<div style="float: right; display: block;">
<asp:Button CssClass="btn btn btn-success" runat="server" ID="btnCreaUser" OnClick="btnCreaUser_Click" Text="Save" />
<button class="btn btn-warning" data-ng-click="vmc.close()">Cancel</button>
</div>
<div style="clear: both;"></div>
</div>
单击取消"按钮时,在控制器中调用该方法:
When the "Cancel" button is clicked, call the method in the controller:
function close() {
var type = "cancel";
$uibModalInstance.dismiss({ type: type, result: null });
}
该页面已正确关闭,但关闭后会重定向到模式页面(具有错误的路径,只有页面名称),并且我遇到了错误.
The page is closed correctly, but after the close there is a redirect to the modal page (with incorrect path, only the page name) and i have an error.
如何防止重定向?
谢谢
更新 使用type ="button"属性,取消"按钮可以正常工作.
UPDATE With the type="button" attribute, the "Cancel" button works correctly.
但是现在我注意到asp:button有同样的问题.
But now i've notice that the asp:button has the same problem.
推荐答案
这是因为button
的默认类型是Submit,它提交表单.使用type="button"
属性:
It's because button
default type is submit, which submits the form. Use type="button"
attribute:
<button class="btn btn-warning" data-ng-click="vmc.close()" type="button">Cancel</button>
这篇关于AngularJS模态关闭,带有进入表单的按钮,导致重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!