【问题标题】:IE -10 -Ajax get method not hitting ControllerIE -10 -Ajax 获取方法未命中控制器
【发布时间】:2014-07-21 05:38:09
【问题描述】:
$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);
}

【问题讨论】:

    标签: asp.net-mvc angular-directive


    【解决方案1】:

    您正在向控制器发布数据,所以我想您应该将属性 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 但你将它转换为字符串然后发送,所以它与控制器的参数不匹配

    【讨论】:

      【解决方案2】:

      我怀疑传递的url是错误的,使用Url.Action()helper生成正确的url:

      改变:

      url: 'Calendar/GetDate'
      

      到:

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

      【讨论】:

        猜你喜欢
        • 2019-09-05
        • 1970-01-01
        • 1970-01-01
        • 2018-10-31
        • 1970-01-01
        • 1970-01-01
        • 2019-09-13
        • 2014-07-27
        • 2016-03-26
        相关资源
        最近更新 更多