在mvc中的post中获取第二个参数null [英] getting second parameter null in post in mvc
本文介绍了在mvc中的post中获取第二个参数null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在控制器中使用httppost动作并使用角度js进行调用。但是第二个参数的getiing始终为null。
我的操作方法
[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);
返回新的JsonResult {Data = new {Services = _Services,Status = isNumericPageSize},};
}
和我的角度js控制器是
this.getServices = function(pageSize,ServiceCategoryId){
return $ http({
方法:post,
url:/ Home / Services_PageSize?pageSize =+ pageSize +& ServiceCategoryId =+ ServiceCategoryId
});
解决方案
http({
method:post,
url:/ Home / Services_PageSize?pageSize =+ pageSize +& ServiceCategoryId =+ ServiceCategoryId
});
你可以试试这个,
this .getServices = function (pageSize,ServiceCategoryId){
var d = {
PageSize:pageSize,
ServiceCategory_Id:ServiceCategoryId
};
return
http({
method: post,
url: / Home / Services_PageSize,
数据:d
});
}
您的变量名称与服务器方法的变量不匹配,我希望它有所帮助。
I am using httppost action in controller and calling using angular js. but getiing second parameter always null.
My action method
[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 }, };
}
and my angular js controller is
this.getServices = function (pageSize, ServiceCategoryId) {
return $http({
method: "post",
url: "/Home/Services_PageSize?pageSize=" + pageSize + "& ServiceCategoryId=" + ServiceCategoryId
});
解决方案
http({ method: "post", url: "/Home/Services_PageSize?pageSize=" + pageSize + "& ServiceCategoryId=" + ServiceCategoryId });
You can try this,
this.getServices = function(pageSize, ServiceCategoryId) { var d = { PageSize: pageSize, ServiceCategory_Id: ServiceCategoryId }; return
http({ method: "post", url: "/Home/Services_PageSize", data: d }); }
Your variable name is not matching with the variable of the server method, I hope it helps.
这篇关于在mvc中的post中获取第二个参数null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文