我先在项目中使用数据库。我将保存到配置文件表,并从部门表中填充下拉列表 在此页面上。如何在profile.cs
的视图中同时使用department.cs
和Profile.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; }
}
答案 0 :(得分:0)
我解决了这个问题。
ProfileController.cs
public ActionResult Create()
{
ViewBag.departman = new SelectList(db.Departments.ToList(), "DepartmentID", "DepartmentName");
return View();
}
Create.cshtml
@Html.DropDownList("Department", ViewBag.departman as SelectList)