1

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 Answer 1

1

I would do like this:

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

@Html.CheckBoxFor(a => myValue)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.