我目前正在 asp.net mvc 4 中工作,我正在尝试将完整日历添加到我的项目中。完整的日历可在此处找到:http://arshaw.com/fullcalendar/
当我单击我的操作链接时,我的日历无法加载。我似乎找不到为什么它不起作用。
代码如下:
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>
所以我目前想知道如何解决这个问题。这是我使用JQuery的第二个项目,所以如果我错过了一些明显的东西,请原谅我。
编辑:在Firefox中运行时,我在firebug中收到以下错误:fullCalendar不是一个函数。
您必须删除:
@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>*@
}
从您的 CSHTML 页面并将它们添加到您的主加载页面。现在它会加载到每个页面上,并且可以正常工作。
=(((((
您没有包含"jquery.js">
从 http://jquery.com 下载最新版本
你已经忘记了包含jQuery库,检查你链接的演示页面,它包括:
<script type='text/javascript' src='/js/fullcalendar-1.5.3/jquery/jquery-1.7.1.min.js'></script>
而您的示例没有。
乍一看,你不需要将 2 个参数传递给你的方法吗?
GetGeplandeTake(双起点,双端(
您的方法是否从视图中调用?如果在方法 上设置断点,则该参数是否有任何值?