I've successfully setup a simple MVC4 internet app that stores model data onto a LocalDb v11.0 SQL server. I generated the database using a code-first approach, however, the Table fields in the database are different than the model database context.
public class Record
{
public int Id { get; set; }
public string PlantLocation { get; set; }
public Plant PlantType { get; set; }
public string Description { get; set; }
}
public class Plant
{
public int Id { get; set; }
public string Name { get; set; }
}
public class RecordContext : DbContext
{
public DbSet<Record> Records { get; set; }
public DbSet<Plant> Plants { get; set; }
}
dbo.Records Table
[Id] INT IDENTITY (1, 1) NOT NULL,
[PlantLocation] NVARCHAR (MAX) NULL,
[Description] NVARCHAR (MAX) NULL,
**[PlantType_Id] INT NULL,**
When i pull-up the table data, every field is populated correctly, with the PlantType_ID showing the Id of the selected Plant.
- How am i supposed to used the PlantType_ID to display the ID of the Plant(or even use this stored data) in my View if PlantType_ID is not in my RecordContext?
I have tried the following to try an get at the ID but to no avail:
@Html.DisplayFor(modelItem => item.PlantType.Id)
I'm not getting build errors or runtime errors if anyone is wondering. Any insight is appreciated.