【问题标题】:Populating a dropdownlist in ASP.NET MVC 5 from another model从另一个模型填充 ASP.NET MVC 5 中的下拉列表
【发布时间】:2015-02-11 19:29:43
【问题描述】:

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

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; }
}

我无法将部门模型中的值提取到 CreateUser 视图中。

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

【问题讨论】:

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


【解决方案1】:

看起来您的问题与下拉列表无关,而与从 MongoDB 填充列表有关。尝试将 DepartmentName 设为虚拟:

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

顺便说一句,我想到这个属性应该命名为“Departments”而不是“DepartmentName”。

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

【讨论】:

    猜你喜欢
    • 2011-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    相关资源
    最近更新 更多