C# 赢得比赛';t从C渲染到Fullcalendar#
我正在DocumentReady中创建fulcalendar,我有一个asp按钮,它运行以下C#函数来获取数据C# 赢得比赛';t从C渲染到Fullcalendar#,c#,jquery,asp.net,json,fullcalendar,C#,Jquery,Asp.net,Json,Fullcalendar,我正在DocumentReady中创建fulcalendar,我有一个asp按钮,它运行以下C#函数来获取数据 public void getAppointments() { List<Appoinment> appoinmentList = new List<Appoinment>(); AppointmentController appointmentController = new AppointmentController
public void getAppointments()
{
List<Appoinment> appoinmentList = new List<Appoinment>();
AppointmentController appointmentController = new AppointmentController();
PublicUserProfileController publicUserProfileController = new PublicUserProfileController();
PublicUserProfile publicUserProfile = new PublicUserProfile();
//appoinmentList = appointmentController.fetchAppointmentByConsultent(Int32.Parse(Session["ICid"].ToString()));
appoinmentList = appointmentController.fetchAppointmentByConsultent(3);
var frontAppoinmentList = new List<object>();
foreach (var appoinment in appoinmentList)
{
publicUserProfile = publicUserProfileController.fetchPublicUserNameById(appoinment.PublicUserProfileId);
var name = publicUserProfile.FirstName + " " + publicUserProfile.LastName;
frontAppoinmentList.Add(new
{
id = appoinment.Id.ToString(),
title = name,
start = appoinment.UtcStartTime,
end = appoinment.UtcEndTime
});
}
// Serialize to JSON string.
JavaScriptSerializer jss = new JavaScriptSerializer();
String json = jss.Serialize(frontAppoinmentList);
var msg = String.Format("<script>loadCal('{0}');</script>", json);
//ClientScript.RegisterStartupScript(GetType(), "hwa", msg, true);
ScriptManager.RegisterClientScriptBlock(this, GetType(), "none", msg, false);
}
protected void btnmonthly_Click(object sender, EventArgs e)
{
getAppointments();
}
render事件不会呈现任何事件,但如果我在控制台中传递此消息,则会呈现事件
var事件=[{id:1,标题:“manoj”,开始:“2017-06-15T22:30:00.000Z”,
完:“2017-06-15T23:30:00.000Z”})
$('appCalendar').fullCalendar('renderEvent',event,true)
这正是我所期望的loadCal函数对我传递的json所做的。这些是我在loadCal中检查断点时为事件数组(eTitle、eId等)设置的值
有人能告诉我为什么没有渲染这些事件吗?我已经做了好几个小时了
更新
我把C#改成了webmethod
[WebMethod(EnableSession = true)]
public static string GetEvents()
{
List<Appoinment> appoinmentList = new List<Appoinment>();
AppointmentController appointmentController = new AppointmentController();
PublicUserProfileController publicUserProfileController = new PublicUserProfileController();
PublicUserProfile publicUserProfile = new PublicUserProfile();
//appoinmentList = appointmentController.fetchAppointmentByConsultent(Int32.Parse(Session["ICid"].ToString()));
appoinmentList = appointmentController.fetchAppointmentByConsultent(3);
var frontAppoinmentList = new List<object>();
foreach (var appoinment in appoinmentList)
{
publicUserProfile = publicUserProfileController.fetchPublicUserNameById(appoinment.PublicUserProfileId);
var name = publicUserProfile.FirstName + " " + publicUserProfile.LastName;
frontAppoinmentList.Add(new
{
id = appoinment.Id.ToString(),
title = name,
start = appoinment.UtcStartTime,
end = appoinment.UtcEndTime
});
}
// Serialize to JSON string.
JavaScriptSerializer jss = new JavaScriptSerializer();
String json = jss.Serialize(frontAppoinmentList);
return json;
}
回调在运行时变为“false”,但我可以看到webmethod在格式化日期后在警报中返回此值
我正在从aspx获取数据,我可以在jquery中读取数据,但我仍然无法渲染偶数。此时我不知道eles要做什么。你能看一下我的代码并指出哪里错了吗?另外,我不理解(start,end,callback)在函数中的用法,因为我在webmethod中根本不使用它
[{ id:1, title:"manoj", start:"2017-06-15T22:30:00.000Z", end:"2017-06-15T23:30:00.000Z" }]
是一个数组。renderEvent
方法需要一个对象。尝试发送
{ id:1, title:"manoj", start:"2017-06-15T22:30:00.000Z", end:"2017-06-15T23:30:00.000Z" }
相反
或者,使用renderEvents
(注意复数)方法()并调用它一次,将其作为参数发送eventList
(在每次事件中,您都必须首先整理日期,就像现在一样,尽管您实际上可以在服务器上这样做以提高效率。使用JSON.NET作为序列化程序将解决此问题)
但是…实际上,这并不是你打算用fullCalendar加载一个大容量事件列表的方式。在客户端完成这一切会非常缓慢,而且你正在一次将所有事件加载到其中——想象一下,当你的应用程序已经运行了一段时间,并且你有一整年或更长的时间时,它会更加缓慢,而且可能布莱:没有人会看那些老的 相反,您应该创建一个单独的服务器方法(例如WebMethod或其他JSON服务),该方法可以接受开始日期和结束日期,并且只返回这些日期之间的相关事件。您可以在启动时告诉fullCalendar此方法的URL,如下所示:
events: "Events.aspx/GetEvents"
然后,当日历启动时,它从服务器请求(通过AJAX)事件仅适用于当时日历上实际显示的日期。当日期或视图更改时,它会请求新日期的更新列表。最重要的是,它会自动执行此操作,而无需您进一步干预。有关此方法的更多详细信息,请参阅
注意:如果您不能让服务器方法完全符合direct JSON提要的要求,您可以使用JavaScript函数作为中介来更改参数的格式和/或更改返回数据的格式,然后再将其传递给fullCalendar。请参阅
如果您实施其中一种解决方案,那么管理日历上的事件就会容易得多。我终于解决了我的问题 我获取数据并作为JSON传递的C#方法是
[WebMethod(EnableSession = true)]
public static string GetEvents()
{
List<Appoinment> appoinmentList = new List<Appoinment>();
AppointmentController appointmentController = new AppointmentController();
PublicUserProfileController publicUserProfileController = new PublicUserProfileController();
PublicUserProfile publicUserProfile = new PublicUserProfile();
//appoinmentList = appointmentController.fetchAppointmentByConsultent(Int32.Parse(Session["ICid"].ToString()));
appoinmentList = appointmentController.fetchAppointmentByConsultent(3);
var frontAppoinmentList = new List<object>();
foreach (var appoinment in appoinmentList)
{
publicUserProfile = publicUserProfileController.fetchPublicUserNameById(appoinment.PublicUserProfileId);
var name = publicUserProfile.FirstName + " " + publicUserProfile.LastName;
frontAppoinmentList.Add(new
{
id = appoinment.Id.ToString(),
title = name,
start = appoinment.UtcStartTime,
end = appoinment.UtcEndTime
});
}
// Serialize to JSON string.
JavaScriptSerializer jss = new JavaScriptSerializer();
String json = jss.Serialize(frontAppoinmentList);
return json;
}
[WebMethod(EnableSession=true)]
公共静态字符串GetEvents()
{
List AppointList=新列表();
任命控制器任命控制器=新任命控制器();
PublicUserProfileController PublicUserProfileController=新的PublicUserProfileController();
PublicUserProfile PublicUserProfile=新的PublicUserProfile();
//appoinmentList=appointmentController.fetchAppointmentByConsultent(Int32.Parse(Session[“ICid”].ToString());
AppointList=AppointController.FetchAppointByConsultant(3);
var frontappingmentlist=新列表();
foreach(指定列表中的var指定)
{
publicUserProfile=publicUserProfileController.fetchPublicUserNameById(appoiment.PublicUserProfileId);
var name=publicUserProfile.FirstName+“”+publicUserProfile.LastName;
FrontAppointList.Add(新增)
{
id=appoiment.id.ToString(),
title=名称,
开始=appoiment.utcstartime,
结束=appoiment.UtcEndTime
});
}
//序列化为JSON字符串。
JavaScriptSerializer jss=新的JavaScriptSerializer();
字符串json=jss.Serialize(FrontAppoinceList);
返回json;
}
我创建Fullcalendar并呈现事件的Jquery是
$(document).ready(function () {
$.ajax({
type: "POST",
url: "AppointmentDiary.aspx/GetEvents",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (doc) {
var events = [];
var docd = doc.d;
var obj = $.parseJSON(doc.d);
console.log(obj);
alert(JSON.stringify(obj));
for (var j = 0; j < obj.length; j++) {
obj[j].start = new Date(parseInt(obj[j].start.replace("/Date(", "").replace(")/",""), 10));
obj[j].start = obj[j].start.toISOString();
obj[j].end = new Date(parseInt(obj[j].end.replace("/Date(", "").replace(")/",""), 10));
obj[j].end = obj[j].end.toISOString();
};
$('#appCalendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventClick: function () {
},
editable: false,
events: obj //Just pass obj to events
})
console.log(events);
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
});
$(文档).ready(函数(){
$.ajax({
类型:“POST”,
url:“AppointmentDialog.aspx/GetEvents”,
contentType:“应用程序/json;字符集=utf-8”,
数据类型:“json”,
成功:功能(doc){
var事件=[];
var docd=doc.d;
var obj=$.parseJSON(doc.d);
控制台日志(obj);
警报(JSON.stringify(obj));
对于(var j=0;jevents: "Events.aspx/GetEvents"
[WebMethod(EnableSession = true)]
public static string GetEvents()
{
List<Appoinment> appoinmentList = new List<Appoinment>();
AppointmentController appointmentController = new AppointmentController();
PublicUserProfileController publicUserProfileController = new PublicUserProfileController();
PublicUserProfile publicUserProfile = new PublicUserProfile();
//appoinmentList = appointmentController.fetchAppointmentByConsultent(Int32.Parse(Session["ICid"].ToString()));
appoinmentList = appointmentController.fetchAppointmentByConsultent(3);
var frontAppoinmentList = new List<object>();
foreach (var appoinment in appoinmentList)
{
publicUserProfile = publicUserProfileController.fetchPublicUserNameById(appoinment.PublicUserProfileId);
var name = publicUserProfile.FirstName + " " + publicUserProfile.LastName;
frontAppoinmentList.Add(new
{
id = appoinment.Id.ToString(),
title = name,
start = appoinment.UtcStartTime,
end = appoinment.UtcEndTime
});
}
// Serialize to JSON string.
JavaScriptSerializer jss = new JavaScriptSerializer();
String json = jss.Serialize(frontAppoinmentList);
return json;
}
$(document).ready(function () {
$.ajax({
type: "POST",
url: "AppointmentDiary.aspx/GetEvents",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (doc) {
var events = [];
var docd = doc.d;
var obj = $.parseJSON(doc.d);
console.log(obj);
alert(JSON.stringify(obj));
for (var j = 0; j < obj.length; j++) {
obj[j].start = new Date(parseInt(obj[j].start.replace("/Date(", "").replace(")/",""), 10));
obj[j].start = obj[j].start.toISOString();
obj[j].end = new Date(parseInt(obj[j].end.replace("/Date(", "").replace(")/",""), 10));
obj[j].end = obj[j].end.toISOString();
};
$('#appCalendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
eventClick: function () {
},
editable: false,
events: obj //Just pass obj to events
})
console.log(events);
},
error: function (xhr, status, error) {
alert(xhr.responseText);
}
});
});