lundi 17 août 2015

Need help for Checkbox as bool? field while rendering from view

I am facing issues with bool? ( Nullable) while rending from MVC3 view.


[MustBeTrue(ErrorMessageResourceName = "EmailConfirmationRequired", ErrorMessageResourceType = typeof(Site))]
 public bool? IsEmailConfirmed { get; set; }  


 @Html.LabelFor(x => x.IsEmailConfirmed, string.Format(CultureInfo.CurrentCulture, "{0}", Site.EmailConfirmText))
<div class="inputClass" id="disabled">
 @if (Model.IsEmailConfirmed == null)
 {  Model.IsEmailConfirmed = false;  }           
  @Html.CheckBoxFor(x => x.IsEmailConfirmed.Value) 
 @Html.ValidationMessageFor(x => x.IsEmailConfirmed)

After ticking the checkbox from the view,the controller is not loading its object asscociated with it. It displays "null", instead of "true" for IsEmailConfirmed. I am suspecting that the IsEmailConfirmed.Value is internally mismatched with the value IsEmailConfirmed. If not, could someone help me to resolve on this please?

Aucun commentaire:

Enregistrer un commentaire