MVC3:带有ajax调用的多个按钮

时间:2013-04-08 17:28:01

标签: ajax asp.net-mvc asp.net-mvc-3

我有一个局部视图,它有两个按钮并与模型绑定(由GET请求生成 - / User / Edit / 1)。我使用了BeginForm而没有指定任何动作名称,因为我想使用模型验证。我已使用ajax配置将操作(URL)分配给“关闭”按钮。当我运行我的应用程序并按下“关闭”按钮时,首先,它使用ajax配置(关闭数据条目)成功执行操作,然后执行POST请求(/ User / Edit / 1)的操作。我想知道,为什么当我按下关闭按钮时执行第二个动作,我怎么能停止执行?

部分视图:_Record.cshtml



@using(Html.BeginForm())
{
    <hr />
    <p>
        <fieldset style="display:inline-block">
            <legend>User</legend>
            <table border="1">
                <tr>
                    <th style="text-align: right; padding-left: 20px;">
                        @Html.LabelFor(model => model.first_name)
                    </th>
                    <td>
                        <div class="editor-field">
                            @Html.TextBoxFor(model => model.first_name, 
new { style = "width:270px;", maxlength = 30 })
                         @Html.ValidationMessageFor(model => model.first_name)
                        </div>
                    </td>
                </tr>
    *****
    *****

            <p>
       <input type="submit" value="Save" style="float: right" />
       <input type="submit" value="Close" onclick="Close()" style="float: right" />
            ?</p>
        </fieldset>
        @Html.ValidationSummary(true)
    </p>
}

1 个答案:

答案 0 :(得分:0)

您的输入类型=“提交”表示当您按此按钮时,您将视图中的模型提交回控制器以进行发布。删除type =“submit”