首页 > 解决方案 > 元组问题@model 元组>

问题描述

我首先在我的项目中使用数据库。我将保存到Profile 表并填写此页面上部门表的下拉列表。我如何同时使用和在视图中?这是一个创建页面。profile.csdepartment.csProfile.cshtml

这是Profile.cs;

public partial class Profile
{
    public int ProfileID { get; set; }
    public string Firstname { get; set; }
    public string Surname { get; set; }
    public string Department { get; set; }
    public string Office { get; set; }
    public string Location { get; set; }
    public string Username { get; set; }
    public string Email { get; set; }
    public string MobileNumber { get; set; }
    public string Title { get; set; }
    public bool Status { get; set; }
    public string Note { get; set; }
    public byte[] Image { get; set; }
    public string Gender { get; set; }
    public Nullable<System.DateTime> RecordDate { get; set; }

}

这是Department.cs;

public partial class Department
{
    public int DepartmentID { get; set; }
    public string DepartmentName { get; set; }
    public string Location { get; set; }

}

标签: asp.net-mvcmodel-view-controllerviewmodeldatabase-first

解决方案


我解决了这个问题。

配置文件控制器.cs

 public ActionResult Create()
    {
        ViewBag.departman = new SelectList(db.Departments.ToList(), "DepartmentID", "DepartmentName");
        return View();
    }

创建.cshtml

@Html.DropDownList("Department", ViewBag.departman as SelectList)

推荐阅读