简体   繁体   English

ASP.NET MVC 3 从动态单选按钮获取值

[英]ASP.NET MVC 3 getting values from dynamic radiobuttons

I have a VERY similar question to this question:我对这个问题有一个非常相似的问题:

ASP.NET MVC C# dynamic radiobuttons getting formcollection ASP.NET MVC C# 动态单选按钮获取表单集合

However, the only difference is, instead of naming the names as:但是,唯一的区别是,而不是将名称命名为:

name="radios[0]" and name="radios[1]", with an 0 and 1, respectively, I need to start mine at 1. name="radios[0]" 和 name="radios[1]",分别是 0 和 1,我需要从 1 开始。

When it comes into public ActionResult Update(string[] radios), it is null because it does not start at 0. I am trying to get this to work using a Dictionary<int, int> radios, and having my names as:当它进入公共 ActionResult Update(string[] radios) 时,它是 null,因为它不是从 0 开始的。我正在尝试使用 Dictionary<int, int> 收音机让它工作,并且我的名字为:

name="radios[1][1 through 3]" and then name="radios[2][1 through 3]" but it doesn't seem to be working. name="radios[1][1 到 3]" 然后 name="radios[2][1 到 3]" 但它似乎没有工作。 Any ideas?有任何想法吗? I can not just subtract 1 from all the values because that's not necessarily the case, I said I am using 1 as an example.我不能只从所有值中减去 1,因为情况不一定如此,我说我以 1 为例。 Thanks, any help would be great!!谢谢,任何帮助都会很棒!

Take a look at phil haacked blog entry , specifically the part: Non-Sequential Indices看看 phil haacked blog entry ,特别是部分:Non-Sequential Indices

To summerise, you need to add 3 new hidden fields, all called radios.Index, one with the value 1, one with value 2 and the other with the value of 3总结一下,你需要添加 3 个新的隐藏字段,都称为 radios.Index,一个值为 1,一个值为 2,另一个值为 3

eg例如

<input type="hidden" name="radios.Index" value="1" />
<input type="hidden" name="radios.Index" value="2" />
<input type="hidden" name="radios.Index" value="3" />

Martin马丁

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM