0

Does anyone know what I need to get the ajax.beginform to work in my MVC4 project? I updated the jQuery library to version 2 and I have included the jquery.validate.js and jquery.validate.unobtrusive.js but the form is still posting to the new page rather than just updating the UpdateTargetId element

I have had a google and a lot of people seem to be having problems with a script called Microsoft.jQuery.Unobtrusive.Ajax but this isn't in my project. Do I need to install this, and if so do I then need to do a find and replace on live so that it uses on instead?

This is the form code:

@using (Ajax.BeginForm("AddImage", "Quote", FormMethod.Post, new AjaxOptions { UpdateTargetId = "Files" }, new { enctype = "multipart/form-data" }))
{
}

This posts to the quote controller addimage action and all that does is write out a string to the screen (which should appear in the Files div) but instead of doing an ajax call it is actually going to the Quote/AddImage page

  • Code! You need to post your code for us to help you! – Alex Polkhovsky Jul 12 '13 at 15:07
  • @KingJulian There isn't much code for this, have posted my form code. The question is more about what js libraries do I need to include to get ajax.beginform to work –  Jul 12 '13 at 15:11

2 Answers2

1

All I had to do in the end was download the latest jquery.unobtrusive-ajax.js through nuget. This has been updated so it works with jquery 2

0

First, you're missing InsertionMode in your AjaxOptions.

Second, it seems you're trying to upload files using Ajax form? You won't be able to. Please see this post, for example.

Finally, Ajax.BeginForm is using jQuery.live() function, which has been removed as of jQuery version 1.9. See this question for more info.

You should install jQuery Migrate Plugin which will restore deprecated features. This will at least restore your Ajax form functionality. Alas, it won't help you upload files through Ajax. But that's a different topic.

Community
  • 1
  • 1
Alex Polkhovsky
  • 3,340
  • 5
  • 29
  • 37
  • +1 for the file upload bit, but the latest version of the unobtrusive ajax works with jquery 1.9 and higher –  Jul 15 '13 at 09:01