简体   繁体   English

如何在动态创建的表单中使用 JQuery Ajax 将表单数据提交到 ASP.NET 核心 MVC 操作

[英]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.我制作了一个包含带有liUL的表单,其中每个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.

相关问题 在 ASP.Net Core MVC 中使用 AJAX 提交表单 - Submit a Form using AJAX in ASP.Net Core MVC 如何获取FormData对象并通过Ajax使用ASP.NET MVC提交表单数据 - How to get FormData object and submit the form data by ajax use asp.net mvc 在Asp.Net mvc 4中使用AJAX提交表单 - Submit form using AJAX in Asp.Net mvc 4 如何使用Jquery AJAX调用MVC Action,然后在MVC中提交表单? - How to call MVC Action using Jquery AJAX and then submit form in MVC? 在ASP.NET MVC 5中使用jQuery成功进行Ajax调用后提交表单 - Submit form after successful ajax call using jQuery in asp.net mvc 5 ASP.NET MVC AJAX表单提交在提交/发布操作后丢失ListBoxFor / MultiSelectList - ASP.NET MVC AJAX Form Submit losing ListBoxFor/MultiSelectList on submit/post action 如何使用JavaScript而不是提交按钮发布ASP.NET MVC Ajax表单 - How to post ASP.NET MVC Ajax form using JavaScript rather than submit button 如何在不使用JS FormData的情况下将文件上传到ASP.NET MVC控制器操作 - How to upload a file to an ASP.NET MVC controller action without using JS FormData 截取的表单提交在 jQuery 和 ASP.NET MVC 上生成阻塞的 ajax 请求 - Intercepted form submit generates a blocking ajax request on jQuery and ASP.NET MVC Asp.Net MVC 5 jQuery验证不适用于带有提交事件的Ajax帖子,显示为有效表单 - Asp.Net MVC 5 Jquery validation not working on ajax post with submit event, showing as valid form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM