0

I'm submitting an Ajax form but when it hits the controller the Request.IsAjax returns false and my page therefore redirects. Anyone know why it would do this?

I have searched the internet and made sure that:

  1. I have the following in my web.config under <appSettings>:

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

  2. I have the following scripts in my page at runtime from viewing the source:

    <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript" />
    
    <script src="/Scripts/modernizr-1.7.min.js" type="text/javascript" />
    
    <script src="/Scripts/jquery-ui-1.8.11.min.js" type="text/javascript" />
    
    <script src="/Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript" />
    
    <script src="/Scripts/jquery.validate.min.js" type="text/javascript" />
    
    <script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript" />
    

Not sure if this is a red herring but I'll mention it because I've hit a brick wall here - when I do view source in Google Chrome only the first script has it's colours formatted, which makes me think I haven't got the syntax right - but it looks right to me! Help!

PeteGO
  • 5,597
  • 3
  • 39
  • 70

2 Answers2

0

Ensure your script refs are above your Ajax call. Load up fiddler and ensure the jquery scripts are found and load.

Adam Tuliper
  • 29,982
  • 4
  • 53
  • 71
  • They are found, and they do load. My scripts are not above my Ajax call - they are at the bottom of the page just before the closing body tag. Could this be the problem? I read somewhere that this is the recommended approach and may improve performance. – PeteGO Sep 19 '11 at 13:05
  • Just tried it, no luck.. in fact my Ajax.Actionlink calls are working, so the scripts must be OK. – PeteGO Sep 19 '11 at 18:30
0

The problem is how I am submitting the form. I was just doing an onchange="submit()" in a dropdown list.

I've now realised that a javascript submit like that is not the same as an ajax submit! :)

If I use an <input type="submit" /> it works.

PeteGO
  • 5,597
  • 3
  • 39
  • 70