[英]How to get the id of selected radio button in Razor code?
I have three radio buttons on my HTML form ie我的 HTML 表单上有三个单选按钮,即
<input type="radio" name="radioBtn" id="rdBtn1" />
<input type="radio" name="radioBtn" id="rdBtn2" />
<input type="radio" name="radioBtn" id="rdBtn3" />
I want to see which radio button is selected so that I can further process.我想查看选择了哪个单选按钮,以便我可以进一步处理。 I am trying this我正在尝试这个
@functions{
var choice = Request.Params["radioBtn"];
}
But the "choice" only returns 'on'.但“选择”只返回“开”。 How can I know which one of these radio buttons are actually active at this point of time?我怎么知道此时哪个单选按钮实际上处于活动状态?
Currently your radio buttons aren't in any way different from one another, as far as the form is concerned.目前,就表单而言,您的单选按钮彼此之间没有任何不同。 Give them values:给他们值:
<input type="radio" name="radioBtn" id="rdBtn1" value="rdBtn1" />
<input type="radio" name="radioBtn" id="rdBtn2" value="rdBtn2" />
<input type="radio" name="radioBtn" id="rdBtn3" value="rdBtn3" />
That way the form can post more than just the binary option of whether or not the radio button was selected.这样,表单可以发布的不仅仅是单选按钮是否被选中的二元选项。 Then choice
should end up with the value
of the one which was selected.然后choice
应该以被选择的value
结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.