I have c# begin form with file upload that looks like this:
@using (Html.BeginForm("New", "Post", FormMethod.Post, new { @class = "form-inline", role = "form", id = "newPostForm", enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(c => c.Post.MinuteID)
@Html.HiddenFor(c => c.Post.UserID)
@Html.TextBoxFor(m => m.PostImage, new { type = "file", name = "PostImage", id = "PostImage", accept = "image/*", @class = "file-input imageInput" })
<button id="postBtn" type="submit" class="btn btn-primary btn-block intbtn">Post </button>
}
This one perfectly works but I want to add some jquery scripts to disable the button and fields when the submit button is clicked. But after doing so, the form submitted becomes empty when it hits my controller. What am I doing wrong? This is my javascripts:
$('#postBtn').click(function () {
$('.imageInput').prop("disabled", true);
$('#postContent').prop("disabled", true);
$('#btnText').text('Saving.. ');
$('#postBtn').prop("disabled", true);
//$('#newPostForm').submit(); -- i tried adding this and changing my button type to 'button' but still empty form values are submitted
});
The reason im doing this is to prevent the button to be clicked multiple times (multiple post), how do I fix this or if there's a better approach to prevent multiple post I'd love to take some suggestions. I want to have a loading effect though thats why I prefer javascript.. I can do this in ajax.post
but I heard enctype = multipart/form-data
doesnt work with ajax. Any help is appreciated.