My model has certain parameters that are read only.
I use a database first approach and use stored procedures for all calls to database.
Examples of parameters in the class that I do not want being added when using the template are DateCreated
, or the Id
columns that are identity (auto num), or a value that is not in a database but is returned from a stored procedure.
Is there a way using the System.ComponentModel.DataAnnotations
to prevent these fields from appearing when I click Add > View > MVC 5 View > and select Create or Edit Template, then choose that particular model?
I have tried using [Editable(false)]
annotation on the models but that doesn't work.
I was hoping that those fields would not be shown in view, thus having me delete them later
My model has certain parameters that are read only.
I use a database first approach and use stored procedures for all calls to database.
Examples of parameters in the class that I do not want being added when using the template are DateCreated
, or the Id
columns that are identity (auto num), or a value that is not in a database but is returned from a stored procedure.
Is there a way using the System.ComponentModel.DataAnnotations
to prevent these fields from appearing when I click Add > View > MVC 5 View > and select Create or Edit Template, then choose that particular model?
I have tried using [Editable(false)]
annotation on the models but that doesn't work.
I was hoping that those fields would not be shown in view, thus having me delete them later
You can use the [ScaffoldColumn(false)]
data annotation. This attribute ensures that the specified property is ignored when scaffolding views for your model.
This attribute is intended to exclude properties from the views generated by the scaffolding templates. It works both for the Add View dialog and for runtime dynamic data.
public class ModelX
{
[ScaffoldColumn(false)] // Prevent this from showing up in templates
public int Id { get; set; }
}