我想要能够提交表单以外的 Html.BeginForm,这是我所拥有的工作在该窗体。
<button type="submit" class="btn btn-default" value="previous" formaction='@Url.Action("Previous", "StudentTest")' >previous </button>
我环顾四周,发现一个解决办法︰ 给你的 Html.BeginForm 这样的名称︰
Html.BeginForm(new {name = "form1" })
然后使用这︰
onclick="document.form1.submit();"
但是它可能使用同样的事情在 Url.Action 而不是 onclick,因为我需要在控制器中的功能吗?
欢呼
试试这个︰
$('#sendButton').click(function(){
$('form[name=yourFormName]').setAttrib('action','actionName');
$('form[name=yourFormName]').submit();
});
或尝试其他方式︰
$('#sendButton').on('click', function () {
var yourData = { tag1 : $('#tag1').val(), tag2 : $('#tag2').val() /*etc..*/ };
$.ajax({
url: '@Url.Action("Action", "Controller")',
type: "POST",
data: yourData ,
success: function (response) {
//sended..
},
error: function (response) {
//not sended..
},
});
});