What is the equivalent in MVC4?
@Html.LabelFor(o => o.Property)
will create a <label>
HTML element referring to the corresponding <input>
element.
Or:
@Html.DisplayFor(o => o.Property)
which will simply output the value of the property as plain text.
or if you want to persist the value on postback you could use either a hidden field (as you already do) or an editor template:
@Html.EditorFor(o => o.Property)
And if you want to have the value of the label displayed on the screen and sent to the server you could use a conjunction of a DisplayFor and HiddenFor elements:
@Html.DisplayFor(o => o.Property)
@Html.HiddenFor(o => o.Property)