I am trying to submit a form using jQuery. The form contains a file upload input which I have disguised using this SO method and am automatically submitting using this SO method. When I check the parameters of _upload
in my controller, type
has a value but file
is null.
Where am I going wrong?
View:
@using (Html.BeginForm("_upload", "Config", null, FormMethod.Post, new { @id = "form_" + Model.imageType }))
{
<label>
<input id="file_@Model.imageType" type="file" name="file" required />
</label>
@Html.Hidden("type",Model.imageType)
}
....
<script>
$(function () {
$('#file_@Model.imageType').change(function () {
$('#form_@Model.imageType').submit();
})
})
</script>
Controller
[HttpPost]
public void _upload(HttpPostedFileBase file, string imageType)
{
//dostuff
}