'Using bootstrap fileinput with .NET core

I'm trying to use Krajee's Bootstrap Fileinput (http://plugins.krajee.com/file-input) and having some problems.

The input field is in a form which has a submit button

<form method="post" enctype="multipart/form-data" asp-action="CreeAnnonce" asp-controller="Vendeur">

My problem is when I upload files with the Fileinput, it runs the action method CreeAnnonce as if I click on the submit button of the form

enter image description here

public async Task<IActionResult> CreeAnnonce(Annonce annonce, IFormFile[] photo)
    {
        ...

I would like to run another action method (in AJAX) when I click on "upload" but I don't know how.

Please help me



Solution 1:[1]

I would like to run another action method (in AJAX) when I click on "upload" but I don't know how.

You can try to add onsubmit to form,and call ajax with onsubmit:

<form method="post" enctype="multipart/form-data" onsubmit="return handleClick()">
    <input id="input-b2" name="input-b2" type="file" class="file" data-show-preview="false">
</form>

js:

function handleClick() {
            alert("handleClick");
        }

result: enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yiyi You