I have the following partial class as a model:
public partial class SourceDevelopmentActivity
{
public int? ActivityID { get; set; }
public string Description { get; set; }
}
I also have the following class to configure the model:
public class SourceDevelopmentActivityMap : EntityTypeConfiguration<SourceDevelopmentActivity>
{
public SourceDevelopmentActivityMap()
{
this.ToTable("SourceDevelopmentActivity");
this.HasKey(t => t.ActivityID);
this.Property(t => t.ActivityID).HasColumnName("ActivityID");
}
}
I pass the configuration into the modelBuilder's configurations on my DBContext's OnModelCreating method:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new SourceDevelopmentActivityMap());
}
When I use the scaffolding option to create the controller and views (CRUD) the edit form has the following setup:
<div class="editor-label">
@Html.LabelFor(model => model.ActivityID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ActivityID)
@Html.ValidationMessageFor(model => model.ActivityID)
</div>
If I change my class to use
public int? SourceDevelopmentActivityID { get; set; }
Then instead of getting the EditorFor
html helper I get the HiddenFor
html helper (which is what I want):
@Html.HiddenFor(model => model.SourceDevelopmentActivityID)
My question is how do I use ActivityID
as my property name but get the scaffolding to understand that it should not be displayed on the edit form (as is the case when I use SourceDevelopmentActivityID
)? I thought this was a pretty straight forward task which makes me think I'm missing something obvious.
Please let me know if you need more info or have any questions. Thanks in advance for any help!