当我使用添加视图对话框生成视图时,如何获取 Entity Frameworks 外键。
我的模型就像
public class System
{
#region Properties
public int SystemId { get; set; }
public string SystemName { get; set; }
#endregion
}
public class Module
{
#region Properties
public int ModuleId { get; set; }
//[Required]
[Display(Name="Module Name")]
public string ModuleName { get; set; }
[Display(Name="Date Added")]
public DateTime DateAdded { get; set; }
//[ForeignKey("CurrentSystem")]
public int SystemId { get; set; }
//[ForeignKey()]
//[ForeignKey("SystemId")]
public System System { get; set; }
#endregion
}
当我单击控制器,然后单击添加视图时,模式打开。我选择了所有需要的细节,然后生成以下内容(我没有包括整个视图)。
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Module</legend>
<div class="editor-label">
@Html.LabelFor(model => model.ModuleName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ModuleName)
@Html.ValidationMessageFor(model => model.ModuleName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DateAdded)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateAdded)
@Html.ValidationMessageFor(model => model.DateAdded)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.SystemId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.SystemId)
@Html.ValidationMessageFor(model => model.SystemId)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
我希望 SystemId 成为下拉列表而不是文本字段。我该怎么做呢 ?