views:

164

answers:

2

I have a few field in my entity that i wish to be non-editable. Looking in the docs it seems like "EditableAttribute" would do the trick. However this is only 4.0

Just wondering if there are other attributes that would have the desire effect. So be clear,

i have a field called "DateRegistered" i wish to display this as string not text field using "Html.EditorFor"

A: 

The [ReadOnly] attribute should work in 3.5.

jfar
A: 

Why are you using an editor template for something that should be read only? Display templates and the <%= Html.DisplayFor(x => x.DateRegistered) %> method seem more appropriate in this case.

Darin Dimitrov
Not if your using EditorFor() to display the entire form at once.
jfar
@jfar, that's not the impression I got from the OPs description. He said `I have a field called "DateRegistered" I wish to display this as string not text field using "Html.EditorFor"`, so I thought that using `DisplayFor` would make more sense, but maybe I got it wrong and the OP uses `EditorFor` the whole model in which case my suggestion won't work as you've pointed out.
Darin Dimitrov
@jfar, also even if you use `EditorForModel`, there's nothing preventing you from customizing the editor template for the model by placing an appropriate partial inside the `~/Views/Shared/EditorTemplates` in which you could use `DisplayFor` for the particular field that needs to be read only.
Darin Dimitrov
@Darin Dimitrov He could also use UIHint("whatever") to display what he wants. I am assuming that if your generating the HTML for each field manually with EditorFor you're probably not asking this question as you could render the field manually just as easily. And anyway he is asking for the attribute.
jfar