// html
<% using (Html.BeginForm("MyAction", "MyController",
new { id = ViewContext.RouteData.Values["id"] },
FormMethod.Post,
new { enctype = "multipart/form-data", class="myForm" }))
{ %>
<input type="file" name="blah" />
<% } %>
// script
$container.find('.myButton').click(function() {
$container.find('.myForm').submit();
});
在提交表单之前,我需要添加一些额外的参数(路由值),这些参数只能在提交时计算。
我该怎么做?
最佳答案
您可以在提交表单之前将隐藏字段附加到表单:
$container.find('.myButton').click(function() {
var form = $container.find('.myForm');
form.append(
$(document.createElement('input'))
.attr('type', 'hidden')
.attr('name', 'somename')
.attr('type', 'somecalculatedvalue')
);
form.submit();
});
关于jquery - 使用 Html.BeginForm 和 jQuery 提交添加动态参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3761051/