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

时间:2015-01-20 22:01:04

标签: c# model-view-controller

我的网页上有6个radiobuttons。当您单击其中一个按钮时,将显示概述。但是未选中所选的单选按钮。您看到按钮显示为已检查一段时间。但与其他的一样,它将再次被取消。

如何检查?

观点:

    <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);
}

1 个答案:

答案 0 :(得分:1)

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

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

以下内容已添加到您的代码中。对你所有的单选按钮做同样的事情,注意你要检查的价值(即1)。

ViewBag.ID_Overzicht==1