user1477388
user1477388

Reputation: 21440

VB ASP.NET MVC 3 Razor CheckboxFor Error "Templates can be used only with field access"

The following code produces the error, "Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions."

Line 66:             </div>
Line 67:             <div class="editor-field">
Line 68:                 @Html.CheckBoxFor(Function(m) m.IsCompanyOwner)
Line 69:                 @Html.ValidationMessageFor(Function(m) m.Company)
Line 70:             </div>

It points the line 68.

I have already read other posts which said to set the type, which I've done in the model:

<DataType(DataType.Text)> _
Public Property IsCompanyOwner As String

But, it still gives me the error. What can I do to fix? Thanks.

Upvotes: 0

Views: 1217

Answers (1)

Forty-Two
Forty-Two

Reputation: 7605

Your trying to bind the checkbox to a string. It must be bound to a bool. See the documantation here

so IsCompanyOwner should be a Boolean, not a string.

Upvotes: 1

Related Questions