0

我有一个局部视图,它有两个按钮并与模型绑定(由 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>
}
4

1 回答 1

0

您的输入 type="submit" 意味着当您按下此按钮时,您将视图中的模型提交回控制器以发布它。删除类型=“提交”

于 2013-04-08T17:40:10.543 回答