I'm working on a view with IList<MyModel>
model assigned and I'm stuck at displaying values with LabelFor
(property name instead of its value is displayed), however, everything works fine with TextBoxFor
even when it's used with the same property.
Part of the view code:
@model IList<MyModel>
@for (var i = 0; i < Model.Count; i++)
{
<tr>
<td>@Html.LabelFor(m => m[i].Code)</td>
<td>@Html.TextBoxFor(m => m[i].Price)</td>
</tr>
}
Model class:
public class MyModel
{
public string Code { get; set; }
public double Price { get; set; }
}
@Html.TextBoxFor(m => m[i].Code)
also works fine so the issue is apparently not related to the property itself.
I could use just Label()
, but I need to POST the values from a form, so I also have to add a hidden field for Code
and I feel it's not the most elegant solution.
Why TextBoxFor
works, but LabelFor
doesn't?