0

我有一个 asp.net MVC 3 razor 视图,它生成这样的复选框:

 @foreach (LoanQuestionIncludesStatement statement in item.Statements)
                {
                    _question = statement.Question;                  
                    @Html.RadioButton("_Q_" + counter.ToString("0#") + _question.ToString(), false, new { @class = "answer " + qOrderedClass, id = "_Q_" + questionOrderedNumber }) @statement.Statement
                    @Html.Hidden("_S_" + counter.ToString("0#") + _question.ToString(), statement.KeyOrStatement) 
                    <br />
                    counter++;
                }

这是生成的html:

<div id="result">
    Please check the correct answer to each of the following questions.
<form method="post" id="frmLoanAuth" action="/CreditRegistry/Verify/VerifyByAccountInfo">        <ol>
        <li class="loanauthquestion">
            <b>Your other obligor's name is</b> <div>
<input type="radio" value="False" name="_Q_002" id="_Q_0" class="answer _QO0">Ann Fillmore<input type="hidden" value="Ann Fillmore" name="_S_002">                    <br>
<input type="radio" value="False" name="_Q_012" id="_Q_0" class="answer _QO0">Alexander Cleveland<input type="hidden" value="Alexander Cleveland" name="_S_012">                    <br>
<input type="radio" value="False" name="_Q_022" id="_Q_0" class="answer _QO0">Abraham Reagan<input type="hidden" value="Abraham Reagan" name="_S_022">                    <br>

                <input type="radio" value="False" name="_N_002" id="_Q_0" class="noneabove _QO0">None of above<br>
            </div>
        </li>
        <li class="loanauthquestion">
            <b>Your guarantor or co-signer's name is</b> <div>
<input type="radio" value="False" name="_Q_035" id="_Q_1" class="answer _QO1">Jude Taylor plc<input type="hidden" value="733824657071694816" name="_S_035">                    <br>
<input type="radio" value="False" name="_Q_045" id="_Q_1" class="answer _QO1">Felix Cleveland plc<input type="hidden" value="733824657071861723" name="_S_045">                    <br>
<input type="radio" value="False" name="_Q_055" id="_Q_1" class="answer _QO1">Eve Cameron plc<input type="hidden" value="733824657071409055" name="_S_055">                    <br>

                <input type="radio" value="False" name="_N_005" id="_Q_1" class="noneabove _QO1">None of above<br>
            </div>
        </li>
        <li class="loanauthquestion">
            <b>Your account balance in a history is in between</b> <div>
<input type="radio" value="False" name="_Q_0610" id="_Q_2" class="answer _QO2">$288,518.79 - $362,585.72<input type="hidden" value="$288,518.79 - $362,585.72" name="_S_0610">                    <br>
<input type="radio" value="False" name="_Q_0710" id="_Q_2" class="answer _QO2">$439,500.00 - $886,344.32<input type="hidden" value="$439,500.00 - $886,344.32" name="_S_0710">                    <br>
<input type="radio" value="False" name="_Q_0810" id="_Q_2" class="answer _QO2">$-51,500.00 - $1,050,052.31<input type="hidden" value="$-51,500.00 - $1,050,052.31" name="_S_0810">                    <br>

                <input type="radio" value="False" name="_N_0010" id="_Q_2" class="noneabove _QO2">None of above<br>
            </div>
        </li>
        </ol>
<input type="hidden" value="3" name="_accountInfoQoNumber" id="_accountInfoQoNumber"><input type="hidden" value="GJMgySz1thj6chtAmRJGr/MaT0YdCY24DZfD1OKju9o5byr/sRPw86gKdEOjjmWGUmSfZ+RJ6AcVVnplGRSiNgFshxaqeRSS/7xAOz3T+q1lEek5whYUL7ggW+PXTX+wVfsNMUrMdeVVVHFjJYYYntxjwt8USjxzY2K0cnDsFqK2vxwa" name="__RequestVerificationToken">        <p><input type="submit" class="readon button" value="Verify"></p>
</form></div>
  1. 我想确保在一组中只选中一个单选按钮,这没有发生

  2. 我想检查控制器动作,哪个单选按钮被选中,我该怎么做?

我在控制器操作中使用此代码:

  var questionRequests = from x in Request.Form.AllKeys
                                   where x.StartsWith("_Q_")
4

2 回答 2

0

如果要确保在一组中只选中一个单选按钮,则必须为该组中的所有单选按钮提供相同的名称。

于 2012-11-09T12:16:19.550 回答
0

id分组时必须是唯一的并且name属性相同

看看这个网址:html单选按钮

于 2012-11-09T12:17:41.083 回答