I'm using MVC framework and on my page i have few checkbox and based on the checkbox user checked i'm showing the div with input/buttons etc... but when the user post the page and if the page has any errors it refresh the entire page and my selection is gone and again i have to check the checkbox to show the div.
My question is how can I persist the selection? How do I update the selection in this case the selection is which checkbox is checked and update the property in the controller EmployeeChk
I have tried something like this:
.Model class
property bool EmployeeChk {get; set;}
property bool EmployerChk {get;set;}
//View page:
<table width="auto">
<tr>
<th>
Employee
</th>
<td>
@Html.CheckBox("Employee")
</td>
</tr>
</table>
<fieldset id="emp" style="@(Model.EmployeeChk ? "" : "display: none")" class="fieldset-auto-width">
<legend>
<legend>
Employee Display
</legend>
@using (Html.BeginForm("EmployeeServer", "EmployeeForm", FormMethod.Post))
{
@Html.ValidationSummary(true)
<div>..... </div>
}
</fieldset>
JQuery:
<script>
$(document).ready(function() {
$('#Employee').change(function() {
if (this.checked) {
$('#emp').show();
}
});
});
</script>
Aucun commentaire:
Enregistrer un commentaire