从另一个模型填充ASP.NET MVC 5中的下拉列表

时间:2015-02-11 19:29:43

标签: c# asp.net-mvc mongodb asp.net-mvc-5

我正在尝试填充包含部门名称的下拉列表。此下拉列表将位于创建新用户的视图中。我有两个单独的模型如下:

public class User : MongoEntity
{
    public User()
    {
        DepartmentName = new List<Department>();
    }

    public string FullName { get; set; }
    public string LoginName { get; set; }
    public string Title { get; set; }
    public List<Department> DepartmentName { get; set; }
    public string TelephoneNumber { get; set; }
    public string Email { get; set; }
}

public class Department : MongoEntity
{
    public string DepartmentName { get; set; }
    public string DepartmentLocation { get; set; }
}

我无法将Department Model中的值拉入CreateUser视图。

我在这个项目中使用MongoDB。任何帮助/反馈将不胜感激。

1 个答案:

答案 0 :(得分:0)

看起来您的问题不是关于dropdownlist,而是关于从MongoDB填充列表。尝试将DepartmentName设为虚拟:

public virtual List<Department> DepartmentName { get; set; }

顺便说一下,我想到这个属性应该命名为#34; Departments&#34;而不是&#34; DepartmentName&#34;。

PS如果没有帮助,请向我们展示更多代码。

相关问题