This is a migrated thread and some comments may be shown as answers.

[Solved] Submitting an Ajax.BeginForm form with javascript/jquery still returning partialview as full page with MVC3

1 Answer 99 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris
Top achievements
Rank 1
Chris asked on 05 Jan 2012, 04:09 PM
Note - this is a problem AND solution to something that took me two days to resolve (but it does have a question for Telerik at the bottom).

The problem was that I was using MVC3 with Ajax.BeginForm and, when using jQuery to submit the form, my partial view returned from the Controller was always returning into a brand new webpage instead of being inserted into the existing div.

Note that using a normal form submit button rather than jQuery was fine.  If the latter isn't even working for you then it's likely that you haven't included the jquery.unobtrusive-ajax.min.js library in your page or set the following key in your site web.config:

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

If the normal submit button does work then carry on reading....

The problem was that two includes to different jQuery libraries (1.5.1 from a manual include and 1.6.4 from an automatic Telerik include) broke the Ajax form submission.  I had to stop Telerik including the 1.6.4 automatically using the line below and then change my manual include to be to the 1.6.4 version rather than 1.5.1 (as I assume that Telerik MVC needs the later version).  I couldn't just remove the manual 1.5.1 include as then I got jQuery undefined errors as the Telerik includes were at the bottom of the _Layout.cshtml page (too late).

I changed:

@Html.Telerik().ScriptRegistrar();
 
to

@Html.Telerik().ScriptRegistrar().jQuery(false);

The full details are over in my post on StackOverflow - StackOverflow question

Question for Telerik: Does the ScriptRegistrar call need to be at the bottom of the _Layout.cshtml page (or equivalent page)?  or can it be at the top in the head which then might resolve the issue of the jQuery undefined problem and therefore having to change the manual include to 1.6.4.

Hopefully - this post might help someone with the same problem.

1 Answer, 1 is accepted

Sort by
0
Trent
Top achievements
Rank 1
answered on 20 Feb 2012, 10:54 PM
Thanks for posting Chris - this has me pulling my hair out. I see this as a workaround, I'd like to know if this is something which is going to be resolved at a later stage...
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Trent
Top achievements
Rank 1
Share this question
or