freiza gen

freiza gen

  • NA
  • 15
  • 0

OnPostAsync works but OnPostUploadAsync doesn't

Apr 26 2023 6:11 PM

I am using razor pages with Entity Framework Core.

when I use OnPostAsync it is being called. But when I use OnPostUpdateAsync method it is not being called. 

This is not being called. I have tried setting breakpoint. Even OnPostUpload doesn't work

public async Task<IActionResult> OnPostUploadAsync(List<IFormFile> MyFiles)
{
 
    int a = await Task.fromResult(0);

    return Page();
}

but when I replace it with the code below it works.

public async Task<IActionResult> OnPostAsync(List<IFormFile> MyFiles)
{
    int k = await Task.FromResult(0);

    return Page();
}

Why? And how do I fix this. Below is my cshtml code.

<form method="post" enctype="multipart/form-data">
    <input type="text" value="" asp-for="mytestmodel.Name"/>
    <input type="file" value="" multiple name="MyFiles"/>
    <input type="submit" value="Submit" />
</form>

 


Answers (3)