$http({
method: 'GET',
dataType: 'json',
url: 'Calendar/GetDate',
params: { calenderId: $scope.CalendarId, fyYear: new Date(viewValue).toUTCString()
}
}).success(function (result) {
alert(result);
});下面的值获取返回,并且它不调用控制器方法
[UMAuthorize]
public ActionResult GetDate(string calenderId, DateTime fyYear)
{
.......
.....
return Json(new { startDate }, JsonRequestBehavior.AllowGet);
}发布于 2014-07-21 05:47:15
您正在向控制器发送数据,因此我想您应该将属性HttpPost放在如下所示:
[UMAuthorize]
[HttpPost]
public ActionResult GetDate(string calenderId, DateTime fyYear)
{
.......
.....
return Json(new { startDate }, JsonRequestBehavior.AllowGet);
}从您的调用控制器使它成为一个Post方法,而不是Get,如下所示:
$http({
method: 'POST',
dataType: 'json',
url: 'Calendar/GetDate',
params: { calenderId: $scope.CalendarId, fyYear: new Date(viewValue)
}
}).success(function (result) {
alert(result);
});您的fyYear对象在控制器中是DateTime,但是您正在将其转换为字符串,然后发送,因此它与控制器的参数不匹配。
发布于 2014-07-21 06:30:27
我认为传递的url是错误的,使用Url.Action()助手生成正确的url:
改变:
url: 'Calendar/GetDate'至:
url: '@Url.Action("GetDate","Calendar")'https://stackoverflow.com/questions/24858329
复制相似问题