开发者

Html.DisplayFor not generating a TextBox in MVC3?

开发者 https://www.devze.com 2023-02-25 20:26 出处:网络
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:

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消