当我在下面运行它的代码bttn click event
但doesn't return a data for success method.
它适用于控制器方法并返回 false(布尔值)作为输出。我需要从 javascript 代码中选择该布尔值。
为什么它不起作用?
Javascript代码如下:
$('#btnClockInTime').off('click').on('click', function () {
var isClockOutTimeCompleted = true;
$.ajax({
url: "/Employees/IsClockOutTimeCompleted",
type: "GET",
dataType: "json",
cache: false,
data: { employeeId: employeeId },
success: function (data) {
if (!data) {
isClockOutTimeCompleted = data;
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
return false;
});
控制器动作方法如下:
[HttpGet]
public JsonResult IsClockOutTimeCompleted(Guid employeeId)
{
var clockingDate = Convert.ToDateTime(DateTime.Today);
var isClockOutTimeCompleted = Repository.IsClockOutTimeCompleted(employeeId, clockingDate);
return Json(isClockOutTimeCompleted, JsonRequestBehavior.AllowGet);
}
存储库代码如下:
public bool IsClockOutTimeCompleted(Guid employeeId, DateTime clockingDate)
{
var clockOutTime = (from c in Catalog.EmployeeClockInOutTimes
where (c.Employee.Id == employeeId && c.Created == clockingDate && c.ClockOut == null)
select c).FirstOrDefault();
return clockOutTime == null;
}
更新 :
响应如下:
更新 2:
屏幕 1:
屏幕 2:
屏幕 3:
如上图所示,我的调试没有进入成功方法。在第二个屏幕之后(在调试时error
)它进入控制器并带来数据。从控制器返回后,第三个屏幕显示状态。知道吗?