在mvc和angularjs中的post中获取第二个参数null

时间:2015-07-09 19:31:55

标签: angularjs asp.net-mvc-4

我在控制器中使用httppost动作并使用角度js进行调用。但是第二个参数的getiing始终为null。

android:layout_width="wrap_content"

我的角度js控制器是

[HttpPost]
        public JsonResult Services_PageSize(string PageSize, string ServiceCategory_Id)
        {
            int n;
            bool isNumericPageSize = int.TryParse(PageSize, out n);
            bool isNumericServiceCategory_Id = int.TryParse(ServiceCategory_Id, out n);
        return new JsonResult { Data = new { Services = _Services, Status =        isNumericPageSize }, };
        }

1 个答案:

答案 0 :(得分:0)

您的第二个参数应该是ServiceCategory_Id而不是ServiceCategoryId(参数名称中遗漏了_)。

this.getServices = function (pageSize, ServiceCategoryId) {
     return $http({
        method: "post",
        url: "/Home/Services_PageSize?pageSize=" + pageSize + "& ServiceCategory_Id=" + ServiceCategoryId
    });
}

更好的选择是应该从post

的数据选项传递调用后数据
this.getServices = function (pageSize, ServiceCategoryId) {
     return $http({
        method: "post",
        url: "/Home/Services_PageSize",
        data: {
           PageSize: pageSize,
           ServiceCategory_Id: ServiceCategoryId
        }
    });
}