Pablo Fernandez
Pablo Fernandez

Reputation: 287390

ASP.Net MVC AJAX link not working

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

<%= 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.

Any ideas what might be wrong?

Upvotes: 2

Views: 4692

Answers (3)

Pablo Fernandez
Pablo Fernandez

Reputation: 287390

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.ActionLink("Log On", "LogOn", "Account", new AjaxOptions {
    UpdateTargetId = "lll",
    Confirm = "blah",
    HttpMethod = "Get"}) %>

Upvotes: 5

tvanfosson
tvanfosson

Reputation: 532445

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.

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

Did you include ajax client scripts in the head section:

  • MicrosoftMvcAjax.js
  • MicrosoftAjax.js

Upvotes: 0

Related Questions