MVC Ajax.ActionLink 找不到 POST 方法
我在我的控制器中声明了一个 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');"
})%>
当它尝试路由此请求时,我收到“未找到”错误。
如果我从控制器中的 UpdateComments 方法中删除 POST 限制,它就可以正常工作。
我缺少什么?
I have a POST method declared in my controller:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateComments(int id, string comments)
{
// ...
}
and an ActionLink in my view:
<%= Ajax.ActionLink("update", "UpdateComments",
new { id = Model.Id, comments = "test" },
new AjaxOptions {
HttpMethod="POST",
OnFailure="alert('fail');",
OnSuccess = "alert('success');"
})%>
I get a "not found" error when it tries to route this request.
If I remove the POST restriction from the UpdateComments method in the controller, it works fine.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
它似乎不喜欢我声明
OnFailure
和OnSuccess
回调的方式。我猜它无法解析我的AjaxOptions
对象,因此忽略了HttpMethod="POST"
设置。我通过将其更改为:
It seems it didn't like the way I was declaring my
OnFailure
andOnSuccess
callbacks. I guess it couldn't parse myAjaxOptions
object so was ignoring theHttpMethod="POST"
setting.I got it working by changing it to:
我现在正在学习 ASP.MVC,我的 Ajax.ActionLink 遇到了这个问题,我得到了 GET 方法,而不是应有的 POST 方法。然后我意识到我没有添加脚本库引用:
添加脚本后它工作正常!
I am learning ASP.MVC at this moment and I had that issue with my Ajax.ActionLink, I got a GET method and not a POST method as it should had been. Then I realize that I didn't add the scripts library reference:
After I adding the script it worked fine!
尝试包括
try including