ASP.NET Core - FormAction 从不传递好的方法

ASP.NET Core - FormAction never pass in the good method

我开始学习 ASP.NET 核心,我的页面上有几个提交按钮,但是当我提交时,post 总是转到相同的方法。一开始,我想在我的表单中插入一个文件上传。

<form>
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <input type="hidden" asp-for="annonce_id" />

    <div class="form-group">
        <label asp-for="annonce_description" class="control-label"></label>
        <input asp-for="annonce_description" class="form-control" />
        <span asp-validation-for="annonce_description" class="text-danger"></span>
    </div>

    <div class="form-group">
        <input type="submit" value="Save" formaction="Edition" formmethod="post" class="btn btn-primary" />
        <input type="submit" value="Save2" formaction="Index2" formmethod="post" class="btn btn-primary" />

        <input type="file" name="file" />
        <input type="submit" name="save" value="upload" form="maform1" formaction="UploadFile" formmethod="post" enctype="multipart/form-data" />

    </div>
</form>

我的控制器:

public ActionResult Detail(int id)
{
    return View("Detail", Connect_Management.BusinessLayer.AnnonceManager.GetOneById(id));
}

[HttpPost]
public ActionResult Edition(Connect_Management.BusinesObject.Annonces annonce)
{
    Connect_Management.BusinessLayer.AnnonceManager.Update(annonce);
    return View();
}

[HttpPost]
public ActionResult Index2(List<IFormFile> files)
{
    //Do something with the files here. 
    return Ok();
}
[HttpPost]
public async Task<IActionResult> UploadFile(IFormFile file)
{
    // full path to file in temp location
    var filePath = Path.GetTempFileName();

    return Ok();
}

它总是使用以下方法:

public ActionResult Edition(Connect_Management.BusinesObject.Annonces annonce)

谢谢

解决方案:

use asp-action="UploadFile instead of formaction="UploadFile"