我将此代码正确传递给其控制器对应方。 但由于某种原因,搜索模型数据只是空值,而pageNumber是正确接收的 我在某个地方犯了错误吗?
$("#NextResult").click(function () {
var xData= document.getElementById("x1").value;
var yData= document.getElementById("y1").value;
var searchModel = {
xval: xData,
yval: yData,
};
var pageNumber = @Model.Page +1;
$.ajax({
url: "/Work/FilterData",
type: "GET",
data: { 'searchModel': searchModel, 'pageNumber': pageNumber },
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
}).success(function (response) {
$('#datas').html(response)
})
});
控制器就是这样
[HttpGet]
public ActionResult FilterData(WorkSearchModel searchModel,int? pageNumber)
{
编辑:
正如所建议我尝试在不同的项目上做两件事(这使得函数不可调用,所以我认为某处有错误)
$("#NextResult").click(function () {
var xData= document.getElementById("x1").value;
var yData= document.getElementById("y1").value;
var searchModel = {
xval: xData,
yval: yData,
pageNumber = @Model.Page +1
};
$.ajax({
url: "/Work/FilterData",
type: "GET",
data: searchModel,
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
}).success(function (response) {
$('#datas').html(response)
})
});
我也尝试过这样做,但没有任何作用(这为searchmodel和pagenumber提供了空值)
$.ajax({
url: "/Work/FilterData",
type: "GET",
data: JSON.stringify(searchModel, pageNumber),
contentType: "application/json;",
答案 0 :(得分:0)
我会将通话从GET更改为POST
答案 1 :(得分:0)
一种解决方案是在查询字符串中逐个发送参数,如此
$("#NextResult").click(function () {
var xData= document.getElementById("x1").value;
var yData= document.getElementById("y1").value;
var pageNumber = @Model.Page +1;
$.ajax({
url: "/Work/FilterData?xval=xData&yval=yData&pageNumber=pageNumber",
type: "GET",
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
}).success(function (response) {
$('#datas').html(response)
})
});
和控制器
[HttpGet]
public ActionResult FilterData(int xval, int yval, int? pageNumber)