kapz
kapz

Reputation: 457

@Html.LabelFor for bool is showing variable name instead of true-false

I have this code line in my MVC 4 application which was converted from MVC 3:

@Html.HiddenFor(model => model.IsInhouse) // IsInhoue is bool

This worked fine when application is MVC 3 but now it's malfunctioning.

I tried displaying the value using @Html.LabelFor(model => model.IsInhouse) and it displays as 'IsInhouse', not saying the content value.

Any clue on this issue is appriciated. I'm new to MVC.

EDIT: Replacing @Html.HiddenFor with <input type="hidden" name="IsInhouse" value="@Html.AttributeEncode(Model.IsInhouse)" id="IsInhouse" /> solved the issue.

Upvotes: 0

Views: 761

Answers (1)

WannaCSharp
WannaCSharp

Reputation: 1898

LabelFor would display its Property Name, that's its purpose. To get its value, use EditorFor

Upvotes: 2

Related Questions