I'm creating a generic interface for editing pages and on some pages eg the start page I need to disable or remove some fields. The form is rendered with Html.EditorFor. What is the best way of doing this?
Asked
Active
Viewed 681 times
1 Answers
1
You could write a custom editor template for the given type (string, decimal, object, ...):
@model string
@Html.TextBox(
"",
ViewData.TemplateInfo.FormattedModelValue,
ViewData
)
and then:
@Html.EditorFor(x => x.Foo)
or in views where you want it to be disabled:
@Html.EditorFor(x => x.Foo, new { disabled = "disabled" })

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
Pretty easy solution but didn't think about it my self. Thanks! – marcus Sep 24 '11 at 10:41