<script type="text/javascript">
$('#fileUpload').submit(function (evt) {
evt.preventDefault();
$.ajax({
url: "/Transport/GridUpload",
type: 'POST',
data: $("#fileUpload").serialize(),
success: function (response) {
alert("it Works");
}
});
});
</script>
I'm trying to post form via Ajax, but it does not work.
Form html:
@using (Html.BeginForm("GridUpload", "Transport", new { tipas = 1 }, FormMethod.Post, new {enctype="multipart/form-data", id = "fileUpload" }))
{
<table style="margin-top:0px;">
<tr>
<td>
<label for="file">Filename:</label>
</td>
<td>
<input type="file" name="file" id="file" />
</td>
<td>
<input type="submit" class="upload-button" value="Upload" />
</td>
</tr>
</table>
}
I get error:
POST http://localhost:3043/Transport/GridUpload 500 (Internal Server Error)
What may be wrong with my code? Am I missing something? For the record, If i remove evt.preventDefault(); everything works, but i need to prevent submitting form without ajax.