gpt4 book ai didi

c# - MVC Ajax.ActionLink 找不到 POST 方法

转载 作者:可可西里 更新时间:2023-11-01 08:10:14 28 4
gpt4 key购买 nike

我在我的 Controller 中声明了一个 POST 方法:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateComments(int id, string comments)
{
// ...
}

在我看来还有一个 ActionLink:

<%= Ajax.ActionLink("update", "UpdateComments", 
new { id = Model.Id, comments = "test" },
new AjaxOptions {
HttpMethod="POST",
OnFailure="alert('fail');",
OnSuccess = "alert('success');"
})%>

当它尝试路由此请求时,我收到“未找到”错误。

如果我从 Controller 中的 UpdateComments 方法中删除 POST 限制,它就可以正常工作。

我错过了什么?

最佳答案

它似乎不喜欢我声明 OnFailureOnSuccess 回调的方式。我猜它无法解析我的 AjaxOptions 对象,因此忽略了 HttpMethod="POST" 设置。

我通过将其更改为:

OnFailure="function() { alert('fail'); }",
OnSuccess="function() { alert('success'); }"

关于c# - MVC Ajax.ActionLink 找不到 POST 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3036915/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com