fea*_*net 13 c# routing asp.net-ajax actionlink asp.net-mvc-2
我在我的控制器中声明了一个POST方法:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateComments(int id, string comments)
{
// ...
}
Run Code Online (Sandbox Code Playgroud)
和我认为的ActionLink:
<%= Ajax.ActionLink("update", "UpdateComments",
new { id = Model.Id, comments = "test" },
new AjaxOptions {
HttpMethod="POST",
OnFailure="alert('fail');",
OnSuccess = "alert('success');"
})%>
Run Code Online (Sandbox Code Playgroud)
尝试路由此请求时出现"未找到"错误.
如果我从控制器中的UpdateComments方法中删除POST限制,它可以正常工作.
我错过了什么?
它似乎不喜欢我宣布我OnFailure
和OnSuccess
回调的方式.我想它无法解析我的AjaxOptions
对象所以忽略了HttpMethod="POST"
设置.
我通过将其更改为:
OnFailure="function() { alert('fail'); }",
OnSuccess="function() { alert('success'); }"
Run Code Online (Sandbox Code Playgroud)