1 回答

TA貢獻1806條經驗 獲得超5個贊
實現此目的的最佳方法是將事件用作完整日歷文檔中描述的JSON 提要模式。
本質上它的工作原理是這樣的:如果您告訴 fullCalendar 控制器操作的 URL,每當日歷中的日期范圍發生變化時(并且它還沒有下載該日期范圍的事件),它就會自動向服務器發出新請求。它還會自動將“開始”和“結束”日期參數附加到請求中 - 因此您的服務器所要做的就是讀取這些參數并在數據庫查詢中使用它們來過濾返回到日歷的結果。您還可以選擇將其他相關數據附加到請求中 - 例如其他過濾器選項。
因此,在您的情況下,您最終會得到如下代碼:
JavaScript - fullCalendar 事件配置:
events: {
? type: "POST",
? url: "/home/GetEvents",
? data: function () { // a function that returns an object
? return {
? ? //your filter object goes here
? };
}
控制器:
[HttpPost]
public JsonResult GetEvents(FiltModel model) {
? ?//...where the FiltModel class includes start and end parameters - ideally these should be DateTime objects, not strings.
? ?//... then, query the database using the filter options in the model, and return JSON in the format required by fullCalendar
}
添加回答
舉報