简体   繁体   中英

Any sort of “Hidden” attribute in System.ComponentModel.DataAnnotations?

I'm trying to write a dynamic control in Microsoft MVC that lets me edit the entity in a grid (specifically using jqgrid). Well, I build my columns and colmodels in my controller based on the entity I'm trying to modify. I'd like to have a way to mark a column as a hidden column, but I'd like to not just create arbitrary Attributes if a standard one already exists. So I'm looking through System.ComponentModel.DataAnnotations which has a lot of good things in it, but not what I'm looking for. Does such an attribute exist? Thanks!

How about using DisplayAttribute.AutoGenerateField ? You could set that to false when you want to not autogen UI for that property.

I just stumbled across this and couldn't use the suggested solution because I don't have .NET 4 available for this project.

So ended up using the EditorBrowsableAttribute , which also controls eg the visibility of properties in the Visual Studio Designer and IntelliSense:

http://msdn.microsoft.com/en-us/library/8a045wyx(v=VS.80).aspx

It's available since .NET 1.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM