ASP.Net MVC:我可以使用的FormCollection来确定哪个单选按钮被选中? [英] ASP.Net MVC: Can I use a FormCollection to determine which radio button was selected?

查看:97
本文介绍了ASP.Net MVC:我可以使用的FormCollection来确定哪个单选按钮被选中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的FormCollection来获得一个ASP.Net MVC视图客户端输入。我使用的是复选框,我只是检查,看看是否的FormCollection的AllKeys名单载我被检查的复选框的名称。我现在需要切换到一个单选按钮,但由于投入需要有相同的名称(这似乎有点傻我),我不能确定哪个单选按钮被选中。

I'm using a FormCollection to get client input on an ASP.Net MVC view. I was using a checkbox, and I would just check to see if the FormCollection's AllKeys list contained the name of the checkbox I was checking. I now need to switch to a radio button, but since the inputs need to have the same name (which seems a bit silly to me), I can't determine which radio button was selected.

或者可以吗?

推荐答案

好吧,如果你有三个单选按钮都具有相同的名称,那么当你得到的值返回的形式集合中,该键的值将是选定的单选按钮的值。这就是他们的工作。它们使用相同的名称作为逻辑分组,因此选择一个,取消选择previous。所以,你可以假设值是选定的单选按钮的值,如果按名称标识该组!

Well if you have three radio buttons all with the same name, then when you get the values back in the form collection, the value of that key will be the value of the selected radio button. That is how they work. They use the same name as a logical grouping so selecting one, deselects the previous. So you can assume that the value is the value of the selected radio button if you identify the group by name!

安德鲁

这篇关于ASP.Net MVC:我可以使用的FormCollection来确定哪个单选按钮被选中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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