MVC Ajax.ActionLink没有找到POST方法 [英] MVC Ajax.ActionLink doesn't find POST method

查看:458
本文介绍了MVC Ajax.ActionLink没有找到POST方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的控制器中声明的POST方法:

I have a POST method declared in my controller:

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

在我看来,一个ActionLink的:

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.

如果我从UpdateComments方法在控制器删除帖子的限制,它工作正常。

If I remove the POST restriction from the UpdateComments method in the controller, it works fine.

我是什么失踪?

推荐答案

看来它不喜欢我宣布我的方式 onFailure处的onSuccess 回调。我想这可能不是我的解析 AjaxOptions 对象,因此被忽略了列举HTTPMethod =POST设置。

It seems it didn't like the way I was declaring my OnFailure and OnSuccess callbacks. I guess it couldn't parse my AjaxOptions object so was ignoring the HttpMethod="POST" setting.

我知道了,改成工作:

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

这篇关于MVC Ajax.ActionLink没有找到POST方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆