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