简体   繁体   English

如何在 Razor 代码中获取所选单选按钮的 ID?

[英]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.

相关问题 如何在数据列表中获取选定的单选按钮文本? - How to get selected radio button text in datalist ? 如何获取剃须刀中单选按钮的值以将其作为参数传递给操作? - How to get the value of a radio button in razor to pass it as a parameter to an action? 在CSHTML Razor .NET中将单选按钮设置为默认选中的选项 - Setting radio button default selected option in CSHTML Razor .NET 在MVC4剃须刀中回发选定的动态单选按钮值 - Posting back selected dynamic radio button value in MVC4 razor 如何使用jQuery获取或设置单选按钮列表的选定索引? - How to get or set Selected index of the Radio Button List using jquery? 如何选中单选按钮以及如何仅控制在列表视图中选择的一个单选按钮 - How to get checked radio button and how to control only one radio button selected in list view 如何通过C#获取组中的选定单选按钮 - How to get selected radio button in group via c# 如何使用MVVM模式获取组中的选定单选按钮? - How to get selected radio button in group using MVVM pattern? 如何获得单选按钮所选项目的文本? - How do I get the text of the radio button selected item? 如何使用jquery获取选定的asp单选按钮? - how can i get the selected asp radio button using jquery?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM