表整理結果我有以下BO:在MVC
public class CinemaSchedule
{
private DateTime showDate;
public DateTime ShowDate
{
get { return showDate; }
set { SetPropertyValue("ShowDate", ref showDate, value); }
}
private TimeSpan showTime;
public TimeSpan ShowTime
{
get { return showTime; }
set { SetPropertyValue("ShowTime", ref showTime, value); }
}
private Cinema cinema;
public Cinema Cinema
{
get { return cinema; }
set { SetPropertyValue("City", ref cinema, value); }
}
}
public class Cinema
{
private string code;
public string Code
{
get { return code; }
set { SetPropertyValue("Code", ref code, value); }
}
private string name;
public string Name
{
get { return name; }
set { SetPropertyValue("Name", ref name, value); }
}
}
在我寫控制器:
model.Schedules = FilmRepository.GetById(eventId).CinemaSchedules;
在視圖中:
<% foreach (var schedule in film.CinemaSchedules)
{ %>
<tr>
<td><a href="#"><%=schedule.Cinema.Name%></a></td>
<td class="time_list">
<ul>
<li><a href="#"><%=TimeSpan.FromSeconds(schedule.ShowTime.Value) %></a></li>
</ul>
</td>
</tr>
<% } %>
結果是:
Cinema 1 19:00:00
Cinema 1 22:00:00
Cinema 2 19:00:00
但我想那是:
Cinema 1 19:00:00 22:00:00
Cinema 2 19:00:00
感謝。
'ToLookup'就是你要的。我會留下來的。 – leppie 2012-02-07 10:48:05
這看起來像一個樞軸 – 2012-02-07 10:53:25