I'm implementing Asp.net Core to my project. In my create razor view, I have to upload file/s which works correctly. I also have a button with id="attachmentremoval"
in the razor, by clicking on it, the attachment should be removed which I couldn't be successful to do it till now. Here is what I have tried till now.
<div class="row">
<div class="col-md-12">
<form asp-action="Create" method="post" enctype="multipart/form-data">
<div class="form-group mt-3">
<label for="files" class="custom-file-upload">
<i class="fa fa-cloud-upload"></i>select file
</label>
<input id="files" name="AttachFile" type="file" style="display:none;">
<span asp-validation-for="FileName" class="text-danger d-block mt-1"></span>
<button id="attachmentremoval">
remove
</button>
</div>
</form>
</div>
</div>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
<script>
$('#files').change(function () {
var arr = $('#file')[0];
var i = $(this).prev('label').clone();
var file = $('#files')[0].files[0].name;
console.log('file:' + i);
$(this).prev('label').text(file);
$("#attachmentremoval").on("click", function () {
/*delete arr.files[0];*/
$('.custom-file-upload').remove();
});
});
</script>
}
I appreciate if anyone could suggest me a solution to remove the attachment and again by clicking the lable it should attach a file.