// 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();
});
Before the form is submitted, I need to add some extra parameters (route values) which can only be calculated at the time of submit.
How do I do that?
You could append a hidden field to the form before submitting it:
$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();
});