4

我已经阅读了许多文章,解释了如何处理表单中的 2 个提交按钮,但没有一篇对我有用。

形式

<form id="myForm">
<input type="submit" name="btngroup" value="remove" />
<input type="submit" name="btngroup" value="activate" />
</form>

js:

$('#myForm').submit(function (e) {
    e.preventDefault();
    var form = $(this);
    $.ajax({
            url: '/Admin/removeDocPermanently',
            type: 'POST',
            DataType: "html",
            data: form.serialize()
    });
});

控制器

[HttpPost]
public ActionResult removeDocPermanently(string btngroup, FormCollection form)
{  
   //btngroup does not get the value of the clicked submit button
}

这是否可以在 js 提交功能或控制器中获得按下的提交按钮?

4

1 回答 1

3

您可以在提交按钮单击时按住提交对象并在提交功能中使用它。

var submitCommand;
$('input:submit').click(function(){
 submitCommand = $(this);
});


$('#myForm').submit(function (e) {
       alert(submitCommand.val());
       //your code
});
于 2013-01-15T10:50:11.837 回答