9
A
回答
12
我假设你在视图中使用这个属性,类似EditorFor
?然后使用:
[Editable(false)]
public string MyProperty {get;set;}
或
@Html.TextBoxFor(x => x.MyProperty, new { readonly = "readonly" })
如果你想有一个类使用的只读公共财产:
public string MyProperty {get; private set;}
相关问题
- 1. 授权属性在MVC 4
- 2. 只读属性
- 3. 只读属性
- 4. 只读属性,在C#6.0
- 5. Threadsafe只读属性
- 6. OData只读属性
- 7. ScriptControlDescriptor.AddProperty&只读属性
- 8. MVC 4外键属性
- 9. C#MVC 4 ControllerName属性
- 10. 只读VS自动(只读)属性
- 11. MVC 4中的多个RegularExpression属性4
- 12. BLToolkit:公共只读属性
- 13. 在ASP.NET MVC 4中实现'ReAuthentication'属性?
- 14. 只读属性不会在ASP.NET MVC模型
- 15. 只读属性在Spring MVC视图模型中查看
- 16. ASP.NET MVC读写集属性
- 17. 只读自定义属性
- 18. Automapper忽略只读属性
- 19. 上一个只读属性
- 20. Object.defineProperty覆盖只读属性
- 21. VB.net自动属性 - 只读?
- 22. 属性:“分配”与“只读”
- 23. 使用weak只读属性?
- 24. jQuery TokenInput - 只读属性
- 25. 删除只读属性
- 26. 复选框只读属性
- 27. 只读属性类扩展
- 28. 只读表单属性
- 29. AS3:属性为只读
- 30. PHP中的只读属性?
谢谢你的职位。我明白了你的观点,但我很好奇的是在模型属性上使用了这个属性。 –
我认为readonly属性只是用于反射的元数据,而不是MVC EditorFor。更多信息在这里:http://msdn.microsoft.com/en-us/library/system.componentmodel.readonlyattribute.aspx这是一个工作只读属性的解决方案:http://stackoverflow.com/questions/18515441/mvc -4-razor-data-annotations-readonly – Marthijn
@ Html.TextBoxFor(x => x.MyProperty,new {@readonly = true})这也在工作 – unique