C# MVC Ajax.ActionLink不';找不到POST方法
我在控制器中声明了一个POST方法:C# MVC Ajax.ActionLink不';找不到POST方法,c#,asp.net-ajax,asp.net-mvc-2,routing,actionlink,C#,Asp.net Ajax,Asp.net Mvc 2,Routing,Actionlink,我在控制器中声明了一个POST方法: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateComments(int id, string comments) { // ... } 在我看来,还有一个ActionLink: <%= Ajax.ActionLink("update", "UpdateComments", new { id = Model.Id, commen
[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限制,它就可以正常工作
我遗漏了什么?它似乎不喜欢我在失败时声明
和成功时声明回调的方式。我猜它无法解析我的AjaxOptions
对象,因此忽略了HttpMethod=“POST”
设置
我将其更改为:
OnFailure="function() { alert('fail'); }",
OnSuccess="function() { alert('success'); }"
FormCollection有一个默认的活页夹
与之相关的总是
初始化集合,然后
不应为空。更多
很可能您有一个空的
使用Ajax.ActionLink时的集合
与使用表单时相反
提交按钮。这是因为
ActionLink方法不会发布任何
在执行AJAX时形成值
要求
我现在正在学习ASP.MVC,我的Ajax.ActionLink遇到了这个问题,我得到了一个GET方法,而不是POST方法。然后我意识到我没有添加脚本库引用:
<script src=”/Scripts/MicrosoftAjax.js” type=”text/javascript”></script>
<script src=”/Scripts/MicrosoftMvcAjax.js” type=”text/javascript”></script>
在我添加脚本后,它工作得很好 尝试包括
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript"></script>
欢迎使用堆栈溢出!你能详细说明一下为什么这会有帮助吗?一个好答案的很大一部分不仅在于理解解决方案,而且在于理解为什么事情从一开始就是一个问题!这些在MVC3和MVC4中已过时。请参阅:这些在MVC3和MVC4中已过时。见: