Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

File upload using IFormFile at application services work with swagger ui,but cant work with blazor page

$
0
0

I have implemented a function in my ABP application service:

public async Task CreateVideoNewsAsync(string VideoName, IFormFile VideoFile)

The function works fine when calling the Swagger interface. However, when using the Blazor interface, I created a CreateModal.cshtml file with the following content:

@model CreateModalModel@inject IStringLocalizer<tennisResource> L@{    Layout = null;}<abp-dynamic-form abp-model="News" asp-page="/News/CreateModal"><abp-modal><abp-modal-header title="@L["NewNews"].Value"></abp-modal-header><abp-modal-body><abp-form-content /></abp-modal-body><abp-modal-footer buttons="@(AbpModalButtons.Cancel|AbpModalButtons.Save)"></abp-modal-footer></abp-modal></abp-dynamic-form> 

The corresponding CreateModal.cshtml.cs file contains the following code:

namespace huake.tennis.Web.Pages.News{    public class CreateModalModel : tennisPageModel    {        [BindProperty]        public CreateNewsViewModel News{ get; set; }        private readonly ICourtAppService _courtAppService;        public CreateModalModel(            ICourtAppService courtAppService)        {            _courtAppService = courtAppService;        }        public void OnGet(string iVideoName, IFormFile iVideoFile)        {            News = new CreateNewsViewModel            {                VideoName = iVideoName,                VideoFile = iVideoFile,            };        }        public async Task<IActionResult> OnPostAsync()        {            //将News.VideoFile实例化            await _courtAppService.CreateVideoNewsAsync(News.VideoName, News.VideoFile);            return NoContent();        }        public class CreateNewsViewModel        {            [Required]            [StringLength(100)]            public required string VideoName { get; set; }            [DisplayName("上传文件")]            public IFormFile VideoFile { get; set; }        }    }}

In debugging, I can see that News.VideoFile is not null when calling the await _courtAppService.CreateVideoNewsAsync(News.VideoName, News.VideoFile); function. However, the system throws an error with the following message:

2024-05-13 10:04:31.402 +08:00 [ERR] ---------- RemoteServiceErrorInfo ----------{"code": null,"message": "您的请求无效!","details": "验证过程中检测到以下错误。\r\n - The VideoFile field is required.\r\n","data": {},"validationErrors": [    {"message": "The VideoFile field is required.","members": ["videoFile"      ]    }  ]}

Can anyone help me identify the issue?


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>