gpt4 book ai didi

jquery - mvc中jquery无法获取json数据

转载 作者:行者123 更新时间:2023-12-01 08:25:27 24 4
gpt4 key购买 nike

我正在 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}
});
};


});

我无法从我的 Controller 操作获取数据:

    [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 数据。但无法在我的日历上显示。我必须做什么?

最佳答案

这里只是一个猜测,但我认为问题是你正在 JSON 序列化 JsonResult 而不是 IList<CalendarDTO> 。而不是这样做:

  JsonResult resultToView = Json(tasksList);
return Json(resultToView,JsonRequestBehavior.AllowGet);

为什么不试试这个呢?

  return Json(tasksList,JsonRequestBehavior.AllowGet);

关于jquery - mvc中jquery无法获取json数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4384935/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com