Considering your question do you want to just select the student doctor when creating a room?
if so im not sure if this will help but you can try this:
In your controller:
SomeContext db = new SomeContext();
public ActionResult Index()
{
ViewBag.studentID = new SelectList(db.AddStudentDoctors, "Id", "Name");
ViewBag.roomID = new SelectList(db.Room, "RoomCode", "RoomNumber");
return View();
}
[HttpPost]
public ActionResult Index(Model AllocateRoom, int studentId, int roomCode)
{
//do some code for adding
//something like
ViewBag.studentID = new SelectList(db.AddStudentDoctors, "Id", "Name", studentId);
ViewBag.roomID = new SelectList(db.Room, "RoomCode", "RoomNumber", roomCode);
return View(AllocateRoom);
}
The above code will populate the names of students using their Id's in the AddStudentDoctors
Once its populated you can take the name and add that to your room table
In your view:
@model AllocateRoom
//layout etc
//add your textbox
//add your dropdown list
@Html.DropDownList("studentID", "Choose Doctor")
@Html.ValidationMessageFor(model => model.studentDoctor)
@Html.DropDownList("roomID", "Choose Room")
@Html.ValidationMessageFor(model => model.room)
important viewbag.studentID - studentID is the 1st parameter for your dropdownlist method same for roomID
If this does not help im sorry for not understanding your question