1
votes

In ASP.NET MVC4, how can I display using Html.CheckBoxFor null as false? That is, I have the code:

@Html.CheckBoxFor(a => a.AttendeesResultLoggedIn.QREmailAllow ?? false)

And i get the error:

Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

My QREmailAllow property is a nullable bool.

1

1 Answers

1
votes

I would do like this:

@{
    var myValue = Model.AttendeesResultLoggedIn.QREmailAllow.HasValue? (bool)Model.AttendeesResultLoggedIn.QREmailAllow : false ;
 }

@Html.CheckBoxFor(a => myValue)