Unable to display checkbox selection and submit to model for processing. Somebody can advise me, , I'm a beginner.
I tried to use JS for client-side display, but then I don't know how to send the checkbox value as true, for processing in the model:
public class IndexModel : PageModel
{
[BindProperty(SupportsGet = true)]
public bool IsChecked { get; set; }
public IndexModel()
{
if (IsChecked == true)
{
any action...
}
else
{
any action...
}
}
I use the script
@{
String textName = "textName" + item.kod;
String chBName = "myCheck" + item.kod;
String fceName = "myFce" + item.kod + "()
}
<script type="text/javascript">
function @fceName {
// Get the checkbox
var checkBox = document.getElementById("@chBName");
// Get the output text
var text = document.getElementById("@textName");
// If the checkbox is checked, display the output text
if (checkBox.checked == true) {
text.style.display = "block";
} else {
text.style.display = "none";
}
}
</script>
even though I wrote, always FALSE
@Html.CheckBoxFor(model => model.IsChecked, new { @IsChecked = "true" , onclick = "@fceName" }
This is works and displays Compare, but I don't know how to send it to the model - get IsChecked is true
<input name="IsChecked" type="checkbox" value="true" id="@chBName" onclick="@fceName">
Aucun commentaire:
Enregistrer un commentaire