使用后如何让单选按钮保持选中状态?

How can I keep the radio button as checked after using it?

我的网页上有 6 个单选按钮。当您单击其中一个按钮时,将显示概览。但是未选中所选的单选按钮。您会看到该按钮暂时显示为已选中。但与其他人相比,它将再次取消选中。

如何检查它?

观点:

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server" >
        <% using (Html.BeginForm("Overige_Statistieken", "Hitdossier", 

        FormMethod.Post, new { id = "frmStatistieken" })) %>
            <% { %>
                <table>
                    <tr>
                        <th class="hitlijst_editie">Selecteer overzicht:</th>
                    </tr>
                    <tr>
                        <td>
                        <%= Html.RadioButton("Overzicht", "1", new
                            {
                                @onclick = "document.getElementById('frmStatistieken').submit();"
                            }) %> Overzicht Alle Nummer 1 hits per week
                        </td>
                    </tr>
                    <tr>
                        <td>
                        <%= Html.RadioButton("Overzicht", "2", new
                            {
                                @onclick = "document.getElementById('frmStatistieken').submit();"
                            })%> Overzicht Alle Tips van de week
                        </td>
                    </tr>
...
        </table>
        <br />
        <br />
        <div>
             <%= Html.Action("Overige_StatistiekenLijst", new { AID_Overzicht = ViewBag.ID_Overzicht })%> <br />   
        </div>
    <% } %>
</asp:Content>

...这是控制器:

public ActionResult Overige_Statistieken(string AID_Overzicht = "1")
{
    ViewBag.ID_Overzicht = AID_Overzicht;
    return View();
}

[HttpPost]
public ActionResult Overige_Statistieken(FormCollection ACollection)
{
    string sID_Overzicht = ACollection["Overzicht"].ToString();
    return Overige_Statistieken(sID_Overzicht);
}

public ActionResult Overige_StatistiekenLijst(string AID_Overzicht)
{
    ViewBag.ID_Overzicht = AID_Overzicht;

    ReadOverigeStatistieken(AID_Overzicht);
    return View(_ListOverzichtModel);
}

有一个重载方法允许您使用 isChecked 参数(第三个参数)设置单选按钮的初始状态。

<%= Html.RadioButton("Overzicht", "1",  (int)ViewBag.ID_Overzicht==1,  new
      {
          @onclick = "document.getElementById('frmStatistieken').submit();"
      }) %>

以下内容已添加到您的代码中。对所有单选按钮执行相同的操作,注意要检查的值(即 1)。

ViewBag.ID_Overzicht==1