【发布时间】:2016-12-01 21:42:40
【问题描述】:
我需要什么
我需要添加下拉菜单和 LabelFor YearID 并从模型 Year 添加到 当前模型部分,使用 Formate 引导程序作为(用 YearID 替换离开 ID)。
我在 MVC 5 Visual Studio 2015 工作,我需要从另一个模型中获取下拉列表。
当前型号名称为 Section:
namespace UniversityData.Models
{
[Table("Section")]
public partial class Section
{
public Section()
{
}
[Key]
public int SecID { get; set; }
[Required]
[StringLength(50)]
public string SecName{ get; set; }
[ForeignKey("Department")]
[DisplayName("DepartmentName")]
public int departID { get; set; }
}
}
我的代码使用 bootstrapis 在我当前的模型部分中下拉离开 ID:
<div class="form-group">
@Html.LabelFor(model => model.departID, "DepartmentName", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("departID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.departID, "", new { @class = "text-danger" })
</div>
</div>
另一个模型年份我想为其生成下拉菜单
[Table("Year")]
public partial class Year
{
public Year()
{
this.department = new HashSet<Department>();
}
[Key]
public int YearID { get; set; }
[Required]
[StringLength(50)]
public string YearName { get; set; }
}
}
我尝试如下:
<div class="form-group">
//如何添加标签替换文本
YearName:
<div class="col-md-10">
@Html.DropDownList("YearID", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
我收到错误:
{“DataBinding:‘System.Data.Entity.DynamicProxies.Department_3D49A8148DA2B6C2F8801CE72951BF7FDBF82503B3A52665397F8B7058E3F8A8’不包含名为‘YearName’的属性。”}
【问题讨论】:
-
谁能帮帮我
标签: html twitter-bootstrap css asp.net-mvc-4 entity-framework-6