Ajax.ActionLink 间歇性地没有命中 POST 控制器方法
Ajax.ActionLink not hitting POST controller method intermittently
我遇到了一个奇怪的问题。我基本上有一个用于分页的 Ajax.ActionLink
:
@Ajax.ActionLink(Model.PaginationText.ToString(), Model.ActionName, Model.RouteValues,
new AjaxOptions
{
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "ajax-append",
LoadingElementDuration = 1000,
OnBegin = "OnAjaxRequestBeginPaging",
OnFailure = "OnAjaxRequestFailure",
OnSuccess = "OnAjaxRequestSuccess",
OnComplete = "OnAjaxRequestComplete",
HttpMethod = "POST"
}, new Dictionary<string, object>() {{"class", "btn btn-more js-only"}, {"id", "ajaxPaging"}})
在我的控制器方法中,我有两个用于 GET 和 POST
的索引方法
[HttpGet]
public ActionResult Index(NewsPage currentPage, int? pageNo)
和
[HttpPost]
public ActionResult Index(NewsPage currentPage, int pageNo, bool? isAjax)
这一切似乎都是正确的,但是当点击时,clink 会间歇性地进入 GET 方法。
我已经调试了几个小时,但我似乎无法始终如一地将代码获取到 POST。
有人对此有什么想法吗?
谢谢
它似乎无法解析您的 AjaxOptions,因此忽略了您的 HttpMethod 设置。尝试使用最少的 AjaxOptions 进行调试。
我最终使用 Ajax.Beginform 而不是 ActionLink,后者似乎工作得更好。
我遇到了一个奇怪的问题。我基本上有一个用于分页的 Ajax.ActionLink
:
@Ajax.ActionLink(Model.PaginationText.ToString(), Model.ActionName, Model.RouteValues,
new AjaxOptions
{
InsertionMode = InsertionMode.InsertAfter,
UpdateTargetId = "ajax-append",
LoadingElementDuration = 1000,
OnBegin = "OnAjaxRequestBeginPaging",
OnFailure = "OnAjaxRequestFailure",
OnSuccess = "OnAjaxRequestSuccess",
OnComplete = "OnAjaxRequestComplete",
HttpMethod = "POST"
}, new Dictionary<string, object>() {{"class", "btn btn-more js-only"}, {"id", "ajaxPaging"}})
在我的控制器方法中,我有两个用于 GET 和 POST
的索引方法[HttpGet]
public ActionResult Index(NewsPage currentPage, int? pageNo)
和
[HttpPost]
public ActionResult Index(NewsPage currentPage, int pageNo, bool? isAjax)
这一切似乎都是正确的,但是当点击时,clink 会间歇性地进入 GET 方法。
我已经调试了几个小时,但我似乎无法始终如一地将代码获取到 POST。
有人对此有什么想法吗?
谢谢
它似乎无法解析您的 AjaxOptions,因此忽略了您的 HttpMethod 设置。尝试使用最少的 AjaxOptions 进行调试。
我最终使用 Ajax.Beginform 而不是 ActionLink,后者似乎工作得更好。