I want the “Choose file” to be optional. That means if user does not click “Choose file”, the default image (/wwwroot/n-image/NoImage.png) is chosen. “Image” is a string property of Article object.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form>
<div>
<div class="form-group">
<label asp-for="Image" class="control-label"></label>
<br />
<div class="custom-file">
<input type="file" asp-for="Image" class="custom-file-input" id="FLFormFIle" />
</div>
<span class="text-danger"></span>
<br />
</div>
<img id="FormFilePrv" src="" style="border:1px; top:20px;margin-left:120px;" />
<div class="form-group">
<br />
<input type="submit" value="Utwórz artykuł" class="btn btn-primary" />
</div>
</div>
</form>
$(".custom-file-input").on("change", function() {
var fileName = $(this).val().split("\").pop();
document.getElementById('FormFilePrv').src = window.URL.createObjectURL(this.files[0])
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
})