mvc DataAnnotations how to make field no editable in 3.5

六月ゝ 毕业季﹏ 提交于 2020-01-03 06:18:53

问题


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"


回答1:


The [ReadOnly] attribute should work in 3.5.




回答2:


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.



来源:https://stackoverflow.com/questions/2876371/mvc-dataannotations-how-to-make-field-no-editable-in-3-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!