如何在Razor代码中获取所选单选按钮的ID? [英] How to get the id of selected radio button in Razor code?

查看:153
本文介绍了如何在Razor代码中获取所选单选按钮的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML表单上有三个单选按钮,即

I have three radio buttons on my HTML form i.e.

<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"];
}

但是选择"仅返回"on".我如何知道这些单选按钮中的哪一个在此时间点实际上处于活动状态?

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" />

通过这种方式,表单不仅可以发布二进制选项,还可以发布是否选择了单选按钮.然后choice应该以所选内容的value结尾.

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.

这篇关于如何在Razor代码中获取所选单选按钮的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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