问题
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"];
}
But the "choice" only returns 'on'. How can I know which one of these radio buttons are actually active at this point of time?
回答1:
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.
来源:https://stackoverflow.com/questions/37420031/how-to-get-the-id-of-selected-radio-button-in-razor-code