Thursday, May 2, 2019

Trouble with HttpPost for Razor Page

Was wondering if anybody can help me with this problem. I am trying to upload images from my web app to BLOB, and when I was watching the tutorial (but it's for MVC), I copy his code into my PageModel. But the HttpPost always show me the warning that it can't be applied to the Razor Page handler method, and I was also wondering if that is the reason the image won't upload to the BLOB.

 [HttpPost] public async Task<ActionResult> UploadAsync() { try { var request = await HttpContext.Request.ReadFormAsync(); if (request.Files ==null) { return BadRequest("Could not upload files"); } var files = request.Files; if (files.Count == 0) { return BadRequest("Could not upload empty files"); } for (int i = 0; i < files.Count; i++) { var blob = _blobContainer.GetBlockBlobReference(GetRandomBlobName(files[i].FileName)); using (var stream = files[i].OpenReadStream()) { await blob.UploadFromStreamAsync(stream); } } return RedirectToAction("Index"); } catch (Exception ex) { ViewData["message"] = ex.Message; ViewData["trace"] = ex.StackTrace; return Page(); } } 
Trouble with HttpPost for Razor Page Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team