[英]How to submit formdata to ASP.NET Core MVC action using JQuery Ajax in a dynamic created form
I have made a Form that contains a UL
with li
where each li
contains inputs and a multiple file form type input, first I load a single row from a predefined HTML document.我制作了一个包含带有li
的UL
的表单,其中每个li
包含输入和多文件表单类型输入,首先我从预定义的 HTML 文档加载单行。 then I take as reference one of the li to create another similar, one contrains a input with file type with a multiple property.然后我以 li 中的一个作为参考来创建另一个类似的,一个包含具有多个属性的文件类型的输入。 Then I have a submit button that onclick
goes to SendProducts
that iterates through each input type on each li
and store the data in a FormData
object each named respectively as if they were a part of a List<Products>
in the MVC pattern.然后我有一个提交按钮, onclick
转到SendProducts
,它遍历每个li
上的每个输入类型,并将数据存储在FormData
object 中,每个分别命名,就好像它们是 MVC 模式中List<Products>
的一部分一样。 The Model contains a IEnumerable<IFormFile>
when I try to post it doesn't go to the action and just refreshed the page Model 包含一个IEnumerable<IFormFile>
当我尝试发布它不 go 到操作并刷新页面
I am using ASP.NET Core 5.02我正在使用 ASP.NET 核心 5.02
https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-5.0#match-name-attribute-value-to-parameter-name-of-post-method https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads?view=aspnetcore-5.0#match-name-attribute-value-to-parameter-name-of-post-方法
the solution is matching the field's name on the FormData assigned key?解决方案是否匹配 FormData 分配键上的字段名称? name you could set it as名称,您可以将其设置为
myFormData.append("products["+(overallObjectCount)+"].Files", inputControl.files[i], inputControl.files[i].name);
if the action's parameter is called Listproducts and contain a如果操作的参数称为 Listproducts 并包含
List<IFormFile> {get;set;} = new List<IFormFile>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.