Is it possible to encapsulate this generically in an editor template
so I can use Html.EditorFor(...) without resorting to a custom
extension?
Of course:
~/Views/Shared/EditorTemplates/Foo.cshtml
:
<div class="control-group">
@Html.Label("")
<div class="controls">
@Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "span3" })
@Html.ValidationMessage("")
</div>
</div>
and then:
@Html.EditorFor(x => x.FirstName, "Foo")
or:
[UIHint("Foo")]
pubilc string FirstName { get; set; }
and then:
@Html.EditorFor(x => x.FirstName)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…