How can I use multiple submit buttons in an HTML form?

HTMLWeb DevelopmentFront End Technology

yes, multiple submit buttons can include in the html form. One simple example is given below.

Here I am using MVC view I am using three buttons with the same name but in different values. In the controller, I am using same name parameter(cmd) which is string type and compare with the value of button's value(Save, Update, Delete).



<html xmlns="">
<head runat="server">
<title>multiple submit button</title>
<% Using Html.BeginForm()%>
<%: Html.ValidationSummary(True) %>
<button type="submit" id="postback1" name="cmd" value="Save" >Save</button>
<button type="submit" id="postback2" name="cmd" value="Update">Update</button>
<button type="submit" id="postback3" name="cmd" value="Delete">Delete</button>
<%: Html.Encode(ViewData("msg"))%>
<% End Using%>


Function multisubmit() As ActionResult
Return View()
End Function

<HttpPost()> _
Function multisubmit(ByVal cmd As String) As ActionResult
If (cmd = "Save") Then
ViewData("msg") = " SAVE"
ElseIf (cmd = "Update") Then
ViewData("msg") = "UPDATE"
ElseIf (cmd = "Delete") Then
ViewData("msg") = "DELETE"
End If
Return View()
End Function
Published on 14-Aug-2018 10:29:37