[英]How can I keep the radio button as checked after using it?
I have on my webpage 6 radiobuttons. 我的网页上有6个单选按钮。 And when you click on one of the buttons, the overview will shown.
当您单击其中一个按钮时,将显示概述。 But the chosen radio button isn't checked.
但是未选中所选的单选按钮。 You see that the button is shown as checked for a while.
您会看到该按钮显示为选中状态一段时间。 But than as the other ones it will be unchecked again.
但是,与其他选项相比,它将再次被取消选中。
How can I keep it checked? 如何保持检查状态?
The view: 风景:
<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>
... and this is the controller: ...这是控制器:
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);
}
There's an overload method that will allow you to set the initial state of the radio button, using the isChecked
parameter (third argument). 有一个重载方法,允许您使用
isChecked
参数(第三个参数)设置单选按钮的初始状态。
<%= Html.RadioButton("Overzicht", "1", (int)ViewBag.ID_Overzicht==1, new
{
@onclick = "document.getElementById('frmStatistieken').submit();"
}) %>
The following was added to your code. 以下内容已添加到您的代码中。 Do that same thing to all your radio buttons paying attention to the value (ie 1) you will check against.
对所有单选按钮执行相同的操作,注意要检查的值(即1)。
ViewBag.ID_Overzicht==1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.