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

查看:31
本文介绍了如何在 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天全站免登陆