AngularJS Modal Closing, with button into Form, ca

2019-09-04 23:13发布

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条回答
劳资没心,怎么记你
2楼-- · 2019-09-04 23:39

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

查看更多
登录 后发表回答