Hello Everyone, I am new to ASP MVC, I am doing the Hostel Management project for learning purposes. I am only using ADO.NET (no EF no Linq). I have two Models Residents and Allocations. I am trying to show the Residents and Allocations (room booking) in the same view.
In my code below, I want to show Resident's information (first name, last name, and email) from Resident's table which is related to the Allocations table, which holds the information about rooms.
In the controller, I am trying to get the resident's information using lists and then check, is there any room allocated to that resident or not.
Will greatly appreciate any help, thanks in advance.
What I have tried:
public ActionResult ManageResidents()
{
List<resident> mlist = new List<resident>();
ResidentDB db = new ResidentDB();
mlist = db.ResidentSelectAll();
foreach (Resident rs in mlist)
{
Allocation mAllocation = new Allocation();
AllocationDB db2 = new AllocationDB();
mAllocation =
db2.AllocationSelect(rs.ResidentAllocation.AllocationID);
rs.ResidentAllocation = mAllocation;
mlist.Add(rs);
}
ViewBag.Residents = mlist;
return View(mlist);
}