How to hide Entity Framework entity properties from strongly typed views? data-annotations entity-framework


I am using Entity Framework in my ASP.NET MVC 4.0 application and I want to know how to prevent or hide fields from my entity from being generated in my strongly typed view? Right now several primary key fields and timestamp fields are being generated on the view which I do not want.

I know setting the property to internal as opposed to public works but I am not sure of the total downstream effect this will have. I prefer to use data annotations on the properties but the ones I have tried prevent Controller scaffolding or make them as hidden fields. I prefer for them to remain public but just not be generated in the strongly typed view.


To generate a strongly typed View, add a new 'View' in Visual Studio and select the class in the dialog to which the view is modeled after. This in turn will create a view with all of the controls that are represented by properties on the class. For example a LastName field is created as below:

@Html.EditorFor(model => model.FirstName)
12/16/2018 6:19:26 PM

Accepted Answer

Answer to the question





before the unwanted properties will prevent de designer to generate scaffolding fields for those properties.

8/14/2012 2:36:25 PM

Popular Answer

To hide a property from the UI via Data Annotations, decorate the property with


and they will be ignored by the editor templates.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow