In a page, I add the code
<RadzenUpload Url="upload/single" Style="margin-bottom: 20px;"
Progress="@((args) => OnProgress(args, "Single file upload"))" />
Then I created a UploadController.cs. But the controller is never triggered. But the website still shows 100% progress after I click the button. No matter adding [Route("[controller]")] and [ApiController]. or not, the controller is never triggered. Can anyone help?
[Route("[controller]")]
[ApiController]
[DisableRequestSizeLimit]
public class UploadController : Controller
{
private readonly IWebHostEnvironment _environment;
public UploadController(IWebHostEnvironment environment)
{
_environment = environment;
}
[HttpPost("upload/single")]
public IActionResult Single(IFormFile file)
{
try
{
UploadFile(file);
return StatusCode(200);
} catch (Exception ex)
{
return StatusCode(500, ex.Message);
}
}
public async Task UploadFile(IFormFile file)
{
if (file!=null && file.Length > 0)
{
var imagePath = @"\Upload";
var uploadPath = _environment.WebRootPath + imagePath;
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
var fullPath = Path.Combine(uploadPath, file.FileName);
using (FileStream fileStream = new FileStream(fullPath, FileMode.Create,FileAccess.Write))
{
await file.CopyToAsync(fileStream);
}
}
}
}
}