开发者

ASP .NET MVC 3 - Submitting an Ajax form redirects instead of updating within page

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/j开发者_C百科query.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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜