I'm trying to move away from hard coding things like text boxes. I'm using MVC3 a开发者_StackOverflow中文版nd I'm doing a very simple test:
@using (Html.BeginForm()) {
@Html.LabelFor(c => c.TestProperty)
@Html.DisplayFor(c => c.TestProperty)
}
LabelFor correctly displays the label. Nothing is generated for the DisplayFor property. Am I missing something? I've done some extensive googling, but I can't figure out why nothing is being generated, must be a simple mistake on my part.
A display template (Html.DisplayFor
) is used (as it name suggests) for displaying a value. If you want editing the value with a textbox you need an editor template:
@Html.EditorFor(c => c.TestProperty)
精彩评论