1

Nearly all my properties in my view model are decorated with [Editable(false)]', but when I scaffold a view, that usesEditorFor` these properties, they are all still editable on the form.

Must I now manually change all EditorFor to DisplayFor to prevet editing? OK, I will eventually change the T4 that generates the edit form, but really, what purpose does this attribute serve then?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • +1. Check [THIS](http://odetocode.com/Blogs/scott/archive/2010/07/25/notes-on-templates-and-data-annotations-in-mvc-2.aspx) post – AliRıza Adıyahşi May 23 '13 at 08:11
  • 1
    "what purpose does this attribute serve then" - the data annotations are used by various different parts of the framework, not just MVC. Just because MVC doesn't respect it, doesn't mean that other parts wouldn't. – Damien_The_Unbeliever May 23 '13 at 08:29

1 Answers1

0

EditorFor works with metadata, so if you want to add html attributes you could always do it. Another option is to simply write a custom template and use TextBoxFor:

<%= Html.TextBoxFor(model => model.Control.PeriodType, 
    new { disabled = "disabled", @readonly = "readonly" }) %> 

Extracted from here:

Html attributes for EditorFor() in ASP.NET MVC

Community
  • 1
  • 1
Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82