这是JS
函数,用于初始化日历:
function InitCalendar() {
$('#calendar').fullCalendar({
events: {
url: '/vacation/SchedulesGet',
type: 'POST',
data: {
title: 'title',
id : 'id',
start: new Date('start'),
end: new Date('end'),
},
error: function () {
alert('there was an error while fetching events!');
},
color: 'yellow',
textColor: 'black'
},
viewRender: function () {
$('.fc-content').attr('data-id', id);
这是Action
:
public virtual JsonResult SchedulesGet()
{
var vacationRequests = new List<dynamic>();
foreach (var item in _service.GetVacationRequestsWithProfiles().ToArray())
{
int vacationLength = ((item.DateEnd - item.DateStart).Days + 1);
string day;
if (vacationLength > 1)
day = " days";
else
day = " day";
vacationRequests.Add(new
{
start = item.DateStart,
end = item.DateEnd,
title = item.Profile.FirstName
+ " " + item.Profile.LastName
+ " (" + item.VacationType.Type
+ ") " + vacationLength + day,
//url = "/VacationRequest/Edit/" + item.Id
id = item.Id
});
}
return Json(vacationRequests, JsonRequestBehavior.AllowGet);
}
我需要设置为div
块data-id
属性。 viewRender: function
中的所有其他功能都可以正常工作。但是使用此行$('.fc-content').attr('data-id', id);
日历不起作用。愿任何人帮助我吗?