AngularJS Modal Closing, with button into Form, cause redirect

大城市里の小女人 提交于 2019-12-12 05:13:35

问题


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.

How can i prevent the redirect?

thanks

UPDATE With the type="button" attribute, the "Cancel" button works correctly.

But now i've notice that the asp:button has the same problem.


回答1:


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>

Read the MDN docs



来源:https://stackoverflow.com/questions/35866732/angularjs-modal-closing-with-button-into-form-cause-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!