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 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="http://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
raja
Published on 14-Aug-2018 10:29:37
Advertisements