ASP.Net MVC AJAX链接不起作用

时间:2022-10-02 03:19:03

I have this link, in an effort to implement AJAX log on, on my page:

为了在我的页面上实现AJAX登录,我有这个链接:

<%= Ajax.ActionLink("Log On", "LogOn", "Account", new AjaxOptions {
    UpdateTargetId = "lll",
    Confirm = "blah"}) %>

There's a div with id lll nearby. When I click the link, I get the blah confirmation (just added for debugging purposes, the behavior without it it's the same) but then nothing happens. No request ever reaches the server (because I have a breakpoint on the LogOn action method). That is in Chrome and IE8. In FF3 it opens the logon view but as a page, it doesn't download it through AJAX.

附近有一个带id id的div。当我点击链接时,我得到了确认(仅为调试目的而添加,没有它的行为是相同的)但是没有任何反应。没有请求到达服务器(因为我在LogOn操作方法上有一个断点)。这是在Chrome和IE8中。在FF3中,它打开登录视图,但作为页面,它不会通过AJAX下载。

Any ideas what might be wrong?

什么想法可能是错的?

3 个解决方案

#1


The problem was that the ajax action link makes a POST request by default and it was being directed to the other LogOn method (the one accepting POST) and that's why I wasn't hitting the breakpoint Also, it was failing because the necessary POST data was not being sent. Adding HttpMethod to the action link fixed it:

问题是ajax动作链接默认发出POST请求,并且它被定向到另一个LogOn方法(接受POST的那个),这就是为什么我没有碰到断点而且,它失败了因为必要的POST数据没被送过。将HttpMethod添加到操作链接修复它:

<%= Ajax.ActionLink("Log On", "LogOn", "Account", new AjaxOptions {
    UpdateTargetId = "lll",
    Confirm = "blah",
    HttpMethod = "Get"}) %>

#2


It sounds like there is some javascript error on the page causing the javascript inserted to handle the AJAX request not to fire. Have you looked at it in FireBug on page load to see if all of your Javascript loading correctly? Also, do your versions of the Microsoft javascript libraries match the version of MVC that you are using? I remember at least once in the progression of versions that I had to manually update my versions of the Microsoft javascript libraries in my project. If your project has existed through multiple versions of MVC, I'd suggest tracking down the new libraries (create a new project and copy them to your old one or open the project archive in the install directory and extract them by hand) and installing them.

听起来好像页面上有一些javascript错误导致插入的javascript处理AJAX请求不会触发。你是否在页面加载时在FireBug中查看它,看看你的所有Javascript加载是否正确?此外,您的Microsoft JavaScript库版本是否与您使用的MVC版本匹配?我记得在版本的进展中至少有一次我不得不在我的项目中手动更新我的Microsoft javascript库版本。如果您的项目已经存在于多个版本的MVC中,我建议您追踪新的库(创建一个新项目并将它们复制到旧项目中,或者在安装目录中打开项目存档并手动提取它们)并安装它们。

#3


Did you include ajax client scripts in the head section:

您是否在头部分中包含了ajax客户端脚本:

  • MicrosoftMvcAjax.js
  • MicrosoftAjax.js

#1


The problem was that the ajax action link makes a POST request by default and it was being directed to the other LogOn method (the one accepting POST) and that's why I wasn't hitting the breakpoint Also, it was failing because the necessary POST data was not being sent. Adding HttpMethod to the action link fixed it:

问题是ajax动作链接默认发出POST请求,并且它被定向到另一个LogOn方法(接受POST的那个),这就是为什么我没有碰到断点而且,它失败了因为必要的POST数据没被送过。将HttpMethod添加到操作链接修复它:

<%= Ajax.ActionLink("Log On", "LogOn", "Account", new AjaxOptions {
    UpdateTargetId = "lll",
    Confirm = "blah",
    HttpMethod = "Get"}) %>

#2


It sounds like there is some javascript error on the page causing the javascript inserted to handle the AJAX request not to fire. Have you looked at it in FireBug on page load to see if all of your Javascript loading correctly? Also, do your versions of the Microsoft javascript libraries match the version of MVC that you are using? I remember at least once in the progression of versions that I had to manually update my versions of the Microsoft javascript libraries in my project. If your project has existed through multiple versions of MVC, I'd suggest tracking down the new libraries (create a new project and copy them to your old one or open the project archive in the install directory and extract them by hand) and installing them.

听起来好像页面上有一些javascript错误导致插入的javascript处理AJAX请求不会触发。你是否在页面加载时在FireBug中查看它,看看你的所有Javascript加载是否正确?此外,您的Microsoft JavaScript库版本是否与您使用的MVC版本匹配?我记得在版本的进展中至少有一次我不得不在我的项目中手动更新我的Microsoft javascript库版本。如果您的项目已经存在于多个版本的MVC中,我建议您追踪新的库(创建一个新项目并将它们复制到旧项目中,或者在安装目录中打开项目存档并手动提取它们)并安装它们。

#3


Did you include ajax client scripts in the head section:

您是否在头部分中包含了ajax客户端脚本:

  • MicrosoftMvcAjax.js
  • MicrosoftAjax.js