Reputation: 1
I use database first on my project.I wil save to Profile table and fill a dropdown from department table on this page . How do I use both profile.cs
and department.cs
in a view in Profile.cshtml
? It is a Creating page.
This is 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; }
}
This is Department.cs
;
public partial class Department
{
public int DepartmentID { get; set; }
public string DepartmentName { get; set; }
public string Location { get; set; }
}
Upvotes: 0
Views: 48
Reputation: 1
I solved the problem.
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)
Upvotes: 0