This project is read-only.

calling the register action using ajax - getting a 404 error

Oct 14, 2009 at 12:59 PM

I can't seem to get the section "Calling the Register Action Method Using Ajax" to work - I get a 404 error when the link "Register for this event" is clicked. I've checked, checked and checked again all the code that I've entered, I've even pasted the code in from the online version of the tutorial, and it still doesn't work. An example of the requested URL is 


Requested URL:



Does this look right? It does to me.


Out of interest, I put a break point in the Register method in the RSVP controller, which never gets called. However, if I remove the AcceptVerbs(HttpVerbs.Post) attribute, the breakpoint does get hit. However, and as can be expected, the message is added to a new page, not updating the page that contains the link. Not sure if this sheds any light on the issue.


Any ideas anyone? I'm at my wits end with this one! 


Oct 19, 2009 at 5:36 PM


Did anyone get to the bottom of this? I have exactly the same issue that I can't get to the bottom of!!




Oct 19, 2009 at 5:43 PM


I never did get to the bottom of this, but...... when moving the code to a partial (in a later section), the issue went away. Its not ideal, as you're not always going to want to use a partial, but at least for the purposes of getting the tutorial working, see if it works. Please let me know if you do find out what was going on!


Kind regards,



Jan 11, 2010 at 6:28 PM

I had the same problem.  You'll smack your head when you realize the simple solution.  The issue is that the tutorial doesn't mention that you need to include the Ajax files to run the Ajax!


Just include these into the Details view and you should be fine.


<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>  
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>

Jan 23, 2011 at 8:21 PM

Got the same error, tried adding the references to the AJAX scripts above, but still not working.

Feb 12, 2011 at 10:14 PM

I also seem to be stuck on this, and have even tried to set the HttpMethod of the Ajax.ActionLink, but still the Controller does not get called.


 <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
<div id="rsvpmsg">
        @if (Request.IsAuthenticated)
            if (Model.IsUserRegistered(Context.User.Identity.Name))
                You are registered for this event</p>
            @Ajax.ActionLink("RSVP for this event",
            new { id = Model.DinnerID }, 
            new AjaxOptions { UpdateTargetId = "rsvpmsg", HttpMethod="Post"})
                <a href="/Account/Logon">Logon</a> to RSVP for this event.</p>

any ideas?

Feb 13, 2011 at 9:12 AM
Edited Feb 13, 2011 at 9:14 AM


Ok, so previously i have mentioned that i had the same problem, and it comes from the fact that MVC 3 uses unobtrusive JavaScript.

To make this work, you have 2 solutions, one is to disable Unobtrusive Javascript in your webconfig file:

    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />

Just set it to false, and during page build, javascript generated for the Action link will be normal inline javascript, that works fine, and results with something like this in HTML:

<a onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), 
{ insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: 'Post', updateTargetId: 'rsvpmsg' });"
href="/RSVP/Register/13">RSVP for this event</a>


Second solution is more to my liking and it is just as simple. You just have to include additional javascript source file in your header:

    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

The resulting javascript generated is unobtrusive, and results with this in HTML:
<a href="/RSVP/Register/13" data-ajax-update="#rsvpmsg" data-ajax-mode="replace" data-ajax-method="Post" data-ajax="true">RSVP for this event</a>

In both cases the resulting functionality is the same, and the second solution is "more in spirit" of new MVC 3.