簡體   English   中英

使用后如何保持單選按鈕為選中狀態?

[英]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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM