接收多部分表单数据 json 参数 null

Receiving multipart form-data json parameter null

我正在尝试从 Postman 接收包含 3 个参数的多部分请求:

我在控制器中收到 fileinteger 都很好,但是 json 的所有字段都为空。 有什么问题吗?

Json

    [Serializable]
    public class ProcessingRecipe
    {
        [JsonPropertyName("fileId")]
        public string FileID { get; set; }
        [JsonPropertyName("srcLang")]
        public string SrcLang { get; set; }

    }

控制器

    [HttpPost]
    [Route(Routes.Routes.File.PROCESS)]
    public async Task<ActionResult<FileProcessResponse>> ProcessFileAsync([FromForm]IFormFile uploadFile,[FromForm] ProcessingRecipe recipe,[FromForm]int aa)
    {
             //the file is ok
            // the int is 33
    }

邮递员

更新 !!!!!

我按照这个用了没用:

自定义活页夹

public class JsonModelBinder : IModelBinder {
    public Task BindModelAsync(ModelBindingContext bindingContext) {
        if (bindingContext == null) {
            throw new ArgumentNullException(nameof(bindingContext));
        }

        // Check the value sent in
        var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
        if (valueProviderResult != ValueProviderResult.None) {
            bindingContext.ModelState.SetModelValue(bindingContext.ModelName, valueProviderResult);

            // Attempt to convert the input value
            var valueAsString = valueProviderResult.FirstValue;
            var result = Newtonsoft.Json.JsonConvert.DeserializeObject(valueAsString, bindingContext.ModelType);
            if (result != null) {
                bindingContext.Result = ModelBindingResult.Success(result);
                return Task.CompletedTask;
            }
        }

        return Task.CompletedTask;
    }
}

控制器动作

public async Task<ActionResult<FileProcessResponse>> ProcessFileAsync([FromForm]IFormFile uploadFile,[ModelBinder(typeof(JsonModelBinder))] ProcessingRecipe recipe)
        {
                 //the file is ok
                // the int is 33
        }

这是

的明确重复

对于您的情况,也许您可​​以尝试以下建议的方法()