POST 和 GET 在由 BeginForm 方法创建的相同表单中

POST and GET in the same form created by BeginForm method

如何使用BeginForm()方法创建一个同时具有搜索功能(从数据库中提取数据)和提交功能(向数据库中添加数据)的表单?我正在查看 MSDN 上的重载,但我似乎没有找到。

代码:

@using (Html.BeginForm()){
    <table>
    @*Bunch of textboxes and dropdown lists*@
    </table>
    <div id=" buttonHolder">
        <input id="Search" type="button" value="Search" />
        <input id="Reset1" type="reset" value="Reset" />
        <input id="Submit1" type="submit" value="Add" />
    </div>
}

您可以在此处使用两种方法:

  1. 使用 AJAX 处理 onsubmit 和 fetch/save 数据(即使使用 Html.BeginForm 也可以,但使用常规 <form ... 更容易)

@using (Html.BeginForm("DoIt", "DoItAction", FormMethod.Post, new { onsubmit = "submitWithAjax(event); return false;" }))

  1. 用不同的action/controller对
  2. 创建两个单独的表格