我创建了一个注册页面。
这是我在数据库中注册的表:
这是我的教育表:
我按照该值填写教育表格和fil下拉列表。
dropdownlist
的代码:
public static class Education
{
public static IEnumerable<SelectListItem> GetEducationList()
{
using (AllameHelliDB db = new AllameHelliDB())
{
var List = (from a in db.Tbl_Educations
orderby a.EduID
select new SelectListItem { Text = a.EduName, Value = a.EduID.ToString() });
return List.ToList();
}
}
}
@Html.LabelFor(model => model.MotherEducation)
@Html.DropDownListFor(model=>model.Paye,Allame_Helli.Models.Education.GetEducationList(),
new { @class = "form-control" })
我需要在EduName
中添加MotherEducation
表格中添加tabel Regsiter
。当我插入数据时返回null。
如何解决这个问题?
答案 0 :(得分:0)
你的drop自己被绑定到Paye
字段,所以这是获取EduID的字段,如果你想获得所选选项的文本EduName,那么你可以从Action本身做到这一点,通过阅读Paye属性并使用此ID检索Education对象,然后填写MotherEducation。
或者您可以为MotherEducation字段添加另一个下拉列表,但您必须同时创建Text和Value = EduName