【发布时间】:2013-08-14 08:44:03
【问题描述】:
我对控制器中的函数进行了 ajax 调用。我需要向该函数传递一个参数,但它没有发生。我的 ajax 调用:
$("#BTN_Plus").click(function () {
var CurrentPage = @Model.CurrentPage;
$.ajax({
type: "POST",
url: "/Accueil/ListerIncidentsHotline",
data: JSON.stringify(CurrentPage),
contentType: 'application/json; charset=utf-8',
success: function (data) {
$("#Affichage").html(data);
}
});
});
我的控制器中的功能:
public PartialViewResult ListerIncidentsHotline( int page = 1)
{
int NextPage = 1 + page;
const int PageSize = 10;
int NumDossier = StructureData.DonneNumDossier((string)Session["Utilisateur"], (string)Session["MotDePasse"]);
IEnumerable<IncidentHotline> ListeIncidents = StructureData.DonneIncidentsHotline(NumDossier);
int NbreIncidents = StructureData.DonneNombreIncidents(NumDossier);
ViewBag.NombreIncidents = NbreIncidents;
var viewModel = new IncidentsPageInfo()
{
NumPages = (int)Math.Ceiling((double)ListeIncidents.Count() / PageSize),
CurrentPage = NextPage,
PageSize = PageSize,
Incidents = ListeIncidents.Skip((NextPage - 1) * PageSize).Take(PageSize),
};
return this.PartialView(viewModel);
}
当我对变量 CurrentPage 发出警报时,它显示了正确的值,但是当涉及到 ajax 调用时,我收到一条错误消息,指出参数为空。不知道有什么问题。
【问题讨论】:
标签: ajax asp.net-mvc-4 controller