ASP.NET MVC 3.0 Beta Unobtrusive JavaScript Problem with Internet Explorer 9 Beta

by Mark Zhou 13. October 2010 08:44

The ASP.NET MVC 3.0 Beta has done a great fundamental change to its AJAX and Client Validation code base to totally build on jQuery and its Validation plug-in. This change lets the MVC framework benefit from the power of the jQuery library, enhance the performance and make it easier to use. The Unobtrusive JavaScript support in ASP.NET MVC 3.0 Beta applies in AJAX and Client Validation features, generates HTML 5 data- prefix attributes, decouples the scripts from the view content (ASPX or Razor). This is cool!

Unobtrusive JavaScript is default enabled in the new ASP.NET MVC 3.0 project template but not enabled in the project which is upgraded from existing ASP.NET MVC 2.0 or 3.0 Preview 1 project. To enable this feature, make sure you added this two JavaScript files and also make sure that your web.config’s appSettings section contains a key “UnobtrusiveJavaScriptEnabled” and its value set to “true”.

~/scripts/jquery-1.4.1.min.js
~/scripts/jquery.unobtrusive-ajax.min.js

Then, you can use

<% using (this.Ajax.BeginForm(new AjaxOptions())) { } %>

to make a form to be submitted asynchronously using AJAX.

OK, so what’s the problem I am mentioning? This does work in Internet Explorer 7, 8, and FireFox 3.6+, but when I tried to test it in Internet Explorer 9, I cannot get the form asynchronously submitted; instead, the form submits as a normal post – the page will be redirected to the URL which is specified by the “action” attribute of that form. So it seems like the unobtrusive AJAX doesn’t work for IE 9 Beta?

I did a research in jquery-unobtrusive-ajax.js file, there are one place to live bind the click event to the elements who defined as a “submit” type (using “: submit” selector, normally the element could be the submit button or HTML input element inside the form element), and one place to live bind the submit event to the form. When I click the button in the form to submit it, the code in the first place is executed, but however, the second place doesn’t (that is, the submit button in the form doesn’t raise the submit event of that form), I also did comparisons – using different browser to test the same code for this case. The result shows that all tested browser except IE 9 Beta, when click a submit button inside a form element, the click event, as well as the submit event of that form, will be fired. Specifically, for IE 9 Beta, only click event of the submit button is fired, submit event of the form isn’t.

Hope this is only a bug in IE 9 Beta, I am expecting a fix in the coming release of IE 9 RC, or RTM.

Tags: , , ,

Comments (5) -

Eric
Eric United States
11/22/2010 8:31:00 AM #

This actually happens to me on IE8 as well, oddly enough.

Reply

mazhou
mazhou United States
11/22/2010 6:11:51 PM #

Have you ever tried on the ASP.NET MVC 3 RC build? It may have resolved this problem already. FireFox 3.5/3.6 works fine in this case.

Reply

Ipodik
Ipodik United States
12/16/2010 11:00:10 PM #

section contains a key web.config’s appSettings  ?

Reply

Catalin
Catalin United States
12/21/2010 7:39:50 AM #

I have the same problem with the new Beta 9 version of Internet Explorer. Firefox seems to work very well.

Reply

Amanda
Amanda United States
1/26/2011 1:33:28 AM #

Thank! for good post. Useful for me and another one.

Reply

Add comment




  Country flag
biuquote
  • Comment
  • Preview
Loading


Translate This Page

About Mark

Mark is a developer who works for building base class libraries and tools for developers.

Mark's Awards

Microsoft Community Contributor

Month List

Who visit this site

Recent Comments

Comment RSS