Computer >> Computer tutorials >  >> Programming >> HTML

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


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

Here I am using MVC VB.net.In 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).

multisubmit.aspx

Example

<html xmlns="https://www.w3.org/1999/xhtml">
<head runat="server">
<title>multiple submit button</title>
</head>
<body>
<div>
<% 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%>
</div>
</body>
</html>

Example

Test.controller
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