0

我正在使用 DayPilot Lite 控件创建计划。我想为每个事件添加附加信息,但不能通过连接定位属性。

我的数据源:

    protected IEnumerable<Schedule> GetUserSched(int userId)
    {
        var query = (from i in _context.UserScheduleMaps
                     where i.UserId == userId
                     select i.ScheduleId).ToList();

        var sched = (from i in _context.Schedules
                     join r in _context.Rooms
                     on i.RoomId equals r.RoomId
                     where query.Contains(i.ScheduleId)
                     select i).ToList();

        return sched;
    }

如果我从第一个表而不是连接表中定位属性,则添加其他属性有效:

    protected void calSched1_BeforeEventRender(object sender, DayPilot.Web.Ui.Events.Calendar.BeforeEventRenderEventArgs e)
    {
        if (e.DataItem.Source != null)
        {
            // e.DataItem["Room.RoomNameOrNumber"] ?
            string location = e.DataItem["RoomId"] as string;
            e.Html = e.Text + ", room: " + location;
        }
    }

如何定位联接表中的属性?

4

1 回答 1

0

解决方案是强制转换e.DataItem.Source为原始类型。然后我可以访问所需的属性。

protected void calSched1_BeforeEventRender(object sender, BeforeEventRenderEventArgs e)
{
    if (e.DataItem.Source != null)
    {
        Schedule sched = (Schedule)e.DataItem.Source;
        e.Html = e.Text + ", room: " + sched.Room.RoomNameOrNumber;
    }
}
于 2017-02-03T20:37:32.380 回答