IE -10 -Ajax get方法没有命中Controller

时间:2014-07-21 05:38:10

标签: asp.net-mvc angular-directive

$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);
}

2 个答案:

答案 0 :(得分:0)

您正在向控制器发布数据,所以我猜你应该把属性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);

});

和ur fyYear对象是控制器中的DateTime,但是您将其转换为字符串然后发送,因此它与控制器的参数不匹配

答案 1 :(得分:0)

我怀疑传递的网址是错误的,请使用Url.Action()帮助生成正确的网址:

变化:

url: 'Calendar/GetDate'

为:

url: '@Url.Action("GetDate","Calendar")'