是的,HTML表单中可以包含多个提交按钮。下面给出一个简单的例子。
在这里,我正在使用MVC VB.net。在视图中,我正在使用三个名称相同但值不同的按钮。在控制器中,我使用的是字符串类型的同名参数(cmd),并与按钮的值(保存,更新,删除)进行比较。
多提交
<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>
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