我有这样的代码:硬编码的下拉菜单(用于创建和更新数据)
当您编辑的用户配置(与相应的CRUD(Controlers +查看)),你会看到一个下拉的SexType(你也可以使用其他一些CRUD编辑)并且将对应于一个SexType表。
public class UserProfile{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public int SexTypeId { get; set; }
public virtual SexType SexType { get; set; }
public class SexType
{
public int SexTypeId { get; set; }
public string SexTypeDescription { get; set; }
public virtual ICollection<UserProfile> UserProfiles { get; set; }
}
public class UserProfileDBContext : DbContext //This creates the database according to the model
{
public DbSet<UserProfile> UserProfiles { get; set; }
public DbSet<SexType> SexType { get; set; }
}
我想要什么: 我想要一个简单的事情,但我不能设法做到这一点:
我想sextype被硬编码(男/女)在我的模型(或控制器)。 不在数据库中。 我不想要任何数据库,但每次创建或更新“UserProfile”上的记录时,只需用“男性/女性”选项可视化下拉菜单。
你能帮我吗?
你的cshtml是什么样子? – 2012-07-11 17:12:45
你要求性而不是性别的任何理由? – CodesInChaos 2012-07-11 18:14:48