我有完整日历的asp.net mvc网站。我还创建了“事件”和“房间”之类的表。在我的事件表中,我有RoomId字段。
这是我的函数的外观:
$(document).ready(function () {
var events = [];
var selectedEvent = null;
FetchEventAndRenderCalendar();
function FetchEventAndRenderCalendar() {
events = [];
$.ajax({
type: "GET",
url: "/CalendarEvent/GetEvents",
success: function (data) {
$.each(data, function (i, v) {
events.push({
eventID: v.Id,
title: v.Job,
description: v.Description,
start: moment(v.Start),
end: v.DutyEnd != null ? moment(v.End) : null,
room: v.RoomId,
});
})
GenerateCalender(events);
},
error: function (error) {
alert('failed');
}
})
}
此刻,日历显示ID。如何引用另一个表?
这是我的控制器:
public JsonResult GetEvents()
{
using (Context dc = new Context())
{
dc.Configuration.LazyLoadingEnabled = false;
var events = dc.Event.ToList();
return new JsonResult { Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
答案 0 :(得分:0)
您需要将事件表与会议室表连接在一起。在控制器方法GetEvents()
中,您可以按照以下方式创建选择查询:
var query = (from event in dc.event
join rooms in dc.rooms on event.roomId equals rooms.roomId
select new
{
eventID: event.Id,
title: event.Job,
description: event.Description,
roomId: room.RoomId,
roomName: room.Name
roomSize: room.Size
}).ToList();
希望这会有所帮助。