I'm working on simple ASP .NET MVC web app which using Entity Framework ( DB First ).
First functionality I'm working on is "Room Booking". For that, I have simple model:
public partial class Room
{
public int Id { get; set; }
public string Name { get; set; }
public string Color { get; set; }
}
public partial class Reservation
{
public int Id { get; set; }
public int RoomId { get; set; }
public int UserId { get; set; }
public System.DateTime Start { get; set; }
public System.DateTime Stop { get; set; }
public string Description { get; set; }
}
public partial class User
{
public int ID { get; set; }
public string UserName { get; set; }
public string FullName { get; set; }
}
I'm trying to create View like UserReservations
, but I don't know how to get User.UserName
and Room.Name
in Reservation
.
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Description)
</td>
<td>
@Html.DisplayFor(modelItem => item.RoomId)
//Here I want to have Room Name instead of RoomId.
</td>
<td>
@Html.DisplayFor(modelItem => item.Start)
</td>
<td>
@Html.DisplayFor(modelitem => item.Stop)
</td>
<td>
</td>
</tr>
}
How to get Room.Name
in Reservation
model ? Do I have to modyify it ( I think there would be modyfications in the future, so model will be updated from database and all of those changes would be discarded).