'Asp MVC CheckBoxFor help needed in postback validation
Probably I'm missing something in this. I need a checkbox to be checked by the user when he submits a form. If he hasn't check the checkbox I need the ModelState.IsValid to be false and return back. All the examples found give me IsChecked() property that I can't get. Here is my code:
model:
[Required(ErrorMessage = "È necessario confermare di aver letto l'informativa sulla privacy.")]
[Display(Name = "Informativa sulla Privacy")]
public bool Privacy { get; set; }
view:
<div class="row mb-3">
<div class="col">
@Html.CheckBoxFor(m => m.Privacy, new { @class = "form-check form-check-inline" })
@Html.LabelFor(m => m.Privacy)<i>*</i>
</div>
</div>
all the other helpers work as expected in the controller, except for the @CheckBoxFor
I see I can get an extension: (m => m.Privacy.IfTrue()), but don't know how to implement it
Thanks for any help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|