0

How to create a form that has a search function (pull data from the database) AND a submit function (add data to the database) at the same time using the BeginForm() method? I am reviewing the overloads on MSDN and I don't seem to find one.

Code:

@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>
}
Dylan Czenski
  • 1,305
  • 4
  • 29
  • 49
  • Are you submitting and searching at the same time? – drew Apr 14 '16 at 19:55
  • @drew not the same time. when `Search` is hit, search, and when `Add` is hit, submit. I just want both methods in the same form – Dylan Czenski Apr 14 '16 at 19:59
  • Possible duplicate of http://stackoverflow.com/questions/442704/how-do-you-handle-multiple-submit-buttons-in-asp-net-mvc-framework/7111222 or http://stackoverflow.com/questions/36555265/asp-net-mvc-core-6-multiple-submit-buttons/36557172 – Will Ray Apr 14 '16 at 19:59

1 Answers1

0

You can use two approaches here:

  1. handle onsubmit and fetch/save data with AJAX (you can do it even with Html.BeginForm but it's easier to go just with regular <form ...)

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

  1. create two separate forms with a different action/controller pair
Mando
  • 11,414
  • 17
  • 86
  • 167