chum of chance
chum of chance

Reputation: 6300

Html.DisplayFor not generating a TextBox in MVC3?

I'm trying to move away from hard coding things like text boxes. I'm using MVC3 and 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.

Upvotes: 0

Views: 1857

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039508

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)

Upvotes: 2

Related Questions