如何使用表单中的按钮调用输入以外的事件?

how to call an event other than the input with a button that is in a form?

我有一个问题,我有一个表单列表,在这个列表的一列中我有两个按钮,但即使我在控制器中为它们指定了一个动作,它们仍会继续调用提交动作,我想知道我如何调用不同的操作,这就是为什么我需要它?将来这些按钮 iram 打开一些隐藏此列表数据的模式可以帮助我吗?谢谢

我的看法:

@model Test.Models.Order

<head>
    <meta charset="utf-8" />
    <title>Teste</title>
    <meta name="viewport" content="width=device-width" />
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">
    <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">

    <link rel="stylesheet" href="http://cdn.datatables.net/1.10.2/css/jquery.dataTables.min.css">
    <script type="text/javascript" src="http://cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js"></script>
    <script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

    @Styles.Render("~/Content/bootstrap.css")
    @Scripts.Render("~/bundles/modernizr")
    <style>
        th {
            height: 10px;
        }
    </style>
    </head>
<body>
        <div id="divbody">
    <nav class="navbar navbar-inverse">
    </nav>
            @using (Html.BeginForm("Save", "Cab", FormMethod.Post))
            {
                <div class="table-responsive" id="table">
                    <table id="myTable" class="table table-striped" cellspacing="0">
                        <thead style="position:static">
                            <tr>
                                <th style="font-size:10px">SELECT</th>
                                <th style="font-size:10px">CONTACT</th>
                                <th></th>
                                <th style="font-size:10px">SUPPLY</th>
                                <th style="font-size:10px">ORDER</th>
                            </tr>
                        </thead>
                        @for (int i = 0; i < Model.listOrder.Count(); i++)
                        {
                            <tr>
                                <td align="center" height="2px">@Html.CheckBoxFor(m => m.listOrder[i].isEdit, new { @onclick = "habilit(" + i + ")", @id = "c" + i })</td>
                                <td colspan="2">
                                    <button disabled="" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-phone-alt"></i></button>
                                    <button disabled="" class="btn btn-xs btn-primary"><i class="glyphicon glyphicon-envelope"></i></button>
                                </td>
                                <td height="2px"> @Html.TextBoxFor(m => m.listOrder[i].supply, new { @readonly = "readonly", @size = "18px", @class = "form-controlSupply" }) </td>
                                <td height="2px"> @Html.TextBoxFor(m => m.listOrder[i].order, new { @readonly = "readonly", @size = "75px", @class = "form-controlOrder" }) </td>
                                <td></td>
                            </tr>
                        }
                    </table>
                </div>
                <br />
                <input type="submit" value="Salve" id="btn" disabled="disabled" class="btn btn-small btn-primary" />
            }
    </div>
 </body>
</html>

如果您希望按钮只是按钮,请使用

<button type="button" disabled="" class="btn btn-xs btn-primary">
    <i class="glyphicon glyphicon-phone-alt"></i>
</button>

这里的关键是type="button"

如果你想要一个按钮调用不同的动作,那么你可以只使用一个锚点,让它看起来像一个按钮

<a href="@Url.Action("Index", "Home")" class="btn btn-xs btn-primary">
    <i class="glyphicon glyphicon-phone-alt"></i>
</a>