提交表单元素具有相同名称 [英] Submitting form elements with the same name

查看:100
本文介绍了提交表单元素具有相同名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格,它允许用户创建额外的行使用JQuery(使用.clone),以便他们可以决定他们需要多少相同的信息提交。我的问题是,我可以不知道如何到我的控制器中访问这些表单项目。

I have a form which allows the user to create extra "rows" using JQuery (using .clone) so that they can decide how many of the same information they need to submit. My issue is that I cannot work out how to access these form items within my controller.

这是正在提交表单可能看起来像这样

the form that is being submitted may look like this

<input type="text" name="Amount" id="Amount">
   <select name="Item">
       <option value="1">Item 1"</option>
       <option value="2">Item 2"</option>
       <option value="3">Item 3"</option>
   </select>
<input type="text" name="Amount" id="Amount">
   <select name="Item">
       <option value="1">Item 1"</option>
       <option value="2">Item 2"</option>
       <option value="3">Item 3"</option>
   </select>
<input type="text" name="Amount" id="Amount">
   <select name="Item">
       <option value="1">Item 1"</option>
       <option value="2">Item 2"</option>
       <option value="3">Item 3"</option>
   </select>

基本上,输入和选择的模块都可以重复无数次。当我向然后我使用的FormCollection形式来访问表单元素控制器。从那里我不确定我怎么可以访问已提交的项目。我想用一个for循环,然后通过类似形式[金额]访问它们的[I],但显然是行不通的。

Basically, the block between input and the select could be repeated an infinite number of times. When I submit to the controller I am then using FormCollection form to access the form elements. from there I am unsure how I can access the items that have been submitted. I thought of using a for loop and then accessing them via something like form["Amount"][i] but obviously that is not going to work.

我要对这个正确的方式,如果是这样,没有任何人有关于如何这可能工作有什么建议?

Am I going about this the right way and if so, does anyone have any suggestions about how this might work?

先谢谢了。

推荐答案

我最终意识到,(腮红的),这jQuery使用发现克隆行内字符串的机制(更换)是基本正则表达式。因此,我只需要躲避方括号和周期。一旦我这样做,我能够使用jQuery创建形式菲尔哈克的博客建议。

I ended up realising that (blush) the mechanism which JQuery uses to find the string within the cloned row (to replace) is basically regex. Thus I just needed to escape the square brackets and period. Once I did this I was able use JQuery to create form as Phil Haack's blog suggested.

到我的下一个问题...!

Onto my next issue...!

这篇关于提交表单元素具有相同名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆