我目前在asp.net mvc 4中工作,我正在嘗試將fullcalendar添加到我的項目中。該fullcalendar在這裏找到:http://arshaw.com/fullcalendar/jquery不能在頁面加載
當我點擊我的ActionLink的,我的日曆將不會加載。我似乎無法找到爲什麼它不起作用。
下面的代碼:
CSHTML
@section JavaScript
{
<link href="@Url.Content("/Content/fullcalendar.css") " rel="stylesheet" type="text/css" />
<script type="text/javascript" src="@Url.Content("/Scripts/jquery-ui-1.8.11.min.js")"></script>
<script type="text/javascript" src="@Url.Content("/Scripts/fullcalendar.js")"></script>
@* <script type="text/javascript" src="@Url.Content("/Scripts/fullcalendar.min.js")"></script>*@
}
@{
ViewBag.Title = "Tijdregistratie";
}
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
header: {
left: 'prev',
center: 'title',
right: 'next'
},
editable: true,
events: "/TijdRegistratie/GetGeplandeTaken/"
});
});
</script>
<div id='calendar'>
</div>
控制器
private TijdRegistratieService.ITijdRegistratieService _tijdRegistratieClient;
public TijdRegistratieController()
{
_tijdRegistratieClient = new TijdRegistratieService.TijdRegistratieServiceClient();
}
public ActionResult TijdRegistratieOverzicht()
{
return View("TijdRegistratieOverzicht");
}
public JsonResult GetGeplandeTaken(double start, double end)
{
String beginDatum = ConvertFromUnixTimestamp(start).ToString();
String eindDatum = ConvertFromUnixTimestamp(end).ToString();
int psnID = (int)HttpContext.Session["userPSNID"];
var geplandeTaken = _tijdRegistratieClient.GetGeregistreerdeTaken(1, beginDatum, eindDatum);
var eventList = from e in geplandeTaken
select new
{
id = e.taakID,
title = e.BeginUur.Substring(0, e.BeginUur.Length - 3) + " - " + e.EindUur.Substring(0, e.EindUur.Length - 3),
start = string.Format("{0:u}", e.BeginDatum),
end = string.Format("{0:u}", e.EindDatum)
//allDay = false
};
var rows = eventList.ToArray();
return Json(rows, JsonRequestBehavior.AllowGet);
}
private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}
Layout.cshtml(全自動裝在每一頁)
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title</title>
<meta name="viewport" content="width=device-width" />
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Content/css")" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="~/Content/autocomplete.css" type="text/css" media="all" />
<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/Scripts/js")"></script>
<link rel="stylesheet" type="text/css" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<link rel="stylesheet" type="text/css" href="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.css" />
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.js"></script>
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/i8n/jquery.mobile.datebox.i8n.en.js"></script>
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/latest/jquery.mobile.datebox.min.js"></script>
<script type="text/javascript" src="http://dev.jtsage.com/cdn/datebox/i8n/jquery.mobile.datebox.i8n.en.js"></script>
@RenderSection("JavaScript", required: false)
<script>
所以我目前wonde響我如何解決這個問題。這是我使用JQuery的第二個項目,如果我錯過了某些明顯的東西,請原諒我。
編輯:在Firefox中運行出現以下錯誤螢火蟲:fullCalendar不是一個函數。
@ EmRA228發佈了正確答案。不幸的是,它被Ohgodwhy錯誤地下調了。 OP顯示的源代碼中沒有提及jQuery。我投票拒絕刪除他的回覆,並會在取消刪除後立即上傳。現在當然還有其他的答案表明,正確的事情與不正確的恕我直言刪除的第一個答案值得信任。 –
似乎不起作用。我的同事(在我做之前曾在這個項目上工作過)突然提到他在不同的頁面加載每一個。因爲這個原因,Jquery會自動加載到每個頁面中。我會將該頁面添加到我的問題中。 –
@darin dimitrov謝謝親愛的。 – EmRa228