I'm trying to call the action FileUploadAsync
from the view. The refresh button that just calls the Index action is working perfectly. The upload button on the view is returning 404 not found... can't think of a reason why.
Controller:
[Area("Admin")]
public class MetricController : Controller
{
public async Task<IActionResult> Index()
{
var allBlobs = await _azureBlobService.ListAsync();
return View(allBlobs);
}
public async Task<IActionResult> FileUploadAsync()
{
var request = await HttpContext.Request.ReadFormAsync();
if (request.Files == null)
{
return BadRequest("files not uploaded");
}
var files = request.Files;
if (files.Count == 0)
{
return BadRequest("files empty");
}
await _azureBlobService.UploadAsync(files);
return RedirectToAction("Index");
}
}
View:
<div class="container-fluid">
<div class="btn btn-primary btn-sm">
<span>Select Files</span><input type="file" id="file" name="selectFiles" class="upload" onchange="DisplayFilesToUpload()" multiple />
</div>
<p id="FilesToUpload"></p>
@if (Model != null && Model.Count > 0)
{
foreach (var item in Model)
{
<div>
<p class="text-secondary">@item</p>
</div>
}
}
<a asp-area="Admin" asp-controller="Metric" asp-action="Index" class="btn btn-outline-primary btn-sm">
Refresh
</a>
<a asp-area="Admin" asp-controller="Metric" asp-action="FileUploadAsync" class="btn btn-outline-primary btn-sm">
Upload
</a>
<a asp-action="DeleteAll" class="btn btn-outline-danger btn-sm">
Delete All
</a>
@section scripts{
<script type="text/javascript" src="~/js/metrics.js"></script>
}
</div>
Edit:
On Startup.cs
the routing is deffined as follows
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{area=Agent}/{controller=Article}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
So this sholudn't be the issue...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…