Hi to everyone.
I’m having difficult obtaining the ErrorMesage from my class in a Surface Controller Form. Everything works as expected except for the validation message when a required checkbox must be ticked. I’ve been trying many things, but the result is always the same: No Error Message.
Following is part of my Model:
[Required(ErrorMessage = "L'Oggetto della richiesta è un campo Obbligatorio")]
[Display(Name = "Oggetto")]
public string Oggetto { get; set; }
[Required(ErrorMessage = "La Descrizione della richiesta è un campo Obbligatorio")]
[Display(Name = "Descrizione")]
public string Descrizione { get; set; }
//[Required(ErrorMessage = "È necessario confermare di aver letto l'informativa sulla privacy.")]
//[Range(typeof(bool), "false", "true", ErrorMessage = "È necessario confermare di aver letto")] // funziona a rovescio
[Range(typeof(bool), "true", "true", ErrorMessage = "È necessario confermare di aver letto l'informativa!")]
[Display(Name = "Informativa sulla Privacy")]
public bool Privacy { get; set; }
As you can see I have tried also with the [Required] attribute.
Following is the View fragment:
@* Privacy *@
<div class="row mb-3">
<div class="col">
@Html.CheckBoxFor(m => m.Privacy, new { @class = "form-check form-check-inline", @style = "width:25px; height:25px" })
@Html.LabelFor(m => m.Privacy)<i>*</i>
@Html.ValidationMessageFor(m => m.Privacy, "", new { @class = "text-danger font-weight-bold blinkingText" })
</div>
</div>
@* Submit *@
<div class="row mb-3">
<div class="col text-center">
<input type="submit" value="Invia Richiesta" class="btn btn-cyan" />
</div>
</div>
the view fragment is wrapped inside a using (Html.BeginUmbracoForm(“Submit”, “FormContatti”))
When I submit with missing fields I get back to the view with all error messages displayed except for the checkbox that has to by ticked:
Anyone can help?
Thanks
René
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/108726-beginumbracoform-validation-for-htmlcheckboxfor-not-returning-error-message
