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!

4

2 回答 2

0

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

于 2011-09-18T21:50:21.023 回答
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.

于 2011-09-19T13:04:50.313 回答