在数据库中插入下拉文本

insert text of dropdown in database

我已经创建了一个注册页面。

这是我的 table 用于在数据库中注册:

这是我的 table 教育:

我用那个值填充教育表和 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" })

我需要从 table 添加 EduName 教育添加 MotherEducationtabel Regsiter 中。当我插入数据时 return null 。

如何解决这个问题?

您的 drop own 绑定到 Paye 字段,因此这是将获取 EduID 的字段,如果您想获取所选选项的文本 EduName,则可以从操作本身,通过读取 Paye 属性 并使用此 ID 检索教育对象,然后填充 MotherEducation。

或者您可以为 MotherEducation 字段添加另一个下拉列表,但您必须使 Text 和 Value = EduName