我正在用asp.net MVC开发应用程序,我的脚本是:
$(document).ready
(
function() {
var officerid = document.getElementById('officerid').value;
url = "/TasksToOfficer/Calender/" + officerid;
var data= function()
{
$.ajax(
{
type: 'GET',
url: url ,
dataType: 'json',
data: {'start' : start,'end' : end}
});
};
});我无法从控制器操作中获取数据:
[HttpGet]
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult Calender(Guid id)
{
List<TasksToOfficer> officersTasks = null;
IList<CalendarDTO> tasksList = new List<CalendarDTO>();
List<TasksToOfficer> officersTasksRecived = null;
if (String.Compare(Convert.ToString(Session["Role"]), RolesEnum.Admin.ToString())!=0)
{
officersTasksRecived = tasks_to_officer_management.GetTasksToOfficers(id);
foreach (TasksToOfficer tt in officersTasksRecived)
{
DateTime dt = Convert.ToDateTime(tt.Date);
tasksList.Add(new CalendarDTO
{
id=tt.Id,
title =tt.Description,
start = ToUnixTimespan(dt),
end = ToUnixTimespan(dt),
url =""}
);
}
}
else
if (String.Compare(Convert.ToString(Session["Role"]), RolesEnum.Officer.ToString()) != 0)
{
officersTasksRecived = tasks_to_officer_management.GetTasksToOfficers(id);
foreach (TasksToOfficer tt in officersTasksRecived)
{
DateTime dt = Convert.ToDateTime(tt.Date);
tasksList.Add(new CalendarDTO
{
id = tt.Id,
title = tt.Description,
start = ToUnixTimespan(dt),
end = ToUnixTimespan(dt),
url = ""
}
);
}
}
JsonResult resultToView = Json(tasksList);
return Json(resultToView,JsonRequestBehavior.AllowGet);
}错误应该是什么?事实上,我正在尝试附加的事件完全日历控制。我正在拾取记录并在我的操作中构建JSon数据。但是无法在我的日历上显示出来。我要做什么?
发布于 2010-12-08 15:31:28
这只是一个猜测,但我认为问题在于您序列化的是JsonResult而不是IList<CalendarDTO>。而不是这样做:
JsonResult resultToView = Json(tasksList);
return Json(resultToView,JsonRequestBehavior.AllowGet);你为什么不试试这个呢?
return Json(tasksList,JsonRequestBehavior.AllowGet);发布于 2010-12-08 22:39:09
试试getJson:
$(document).ready(function () {
var officerid = document.getElementById('officerid').value;
$.getJSON("/TasksToOfficer/Calender/" + officerid, function (data) {
// do something with 'data'
});
});您可以将浏览器指向如下所示的操作:http://yourdomain.com/TasksToOfficer/Calender/someID,并查看是否会获得一些数据。只需将'someID‘替换为某个现有的ID即可。
https://stackoverflow.com/questions/4384935
复制相似问题