6

I'm trying to look for good (in-depth) explanation on what happens when you use MVC ajax helpers. What events and css classes get added. I can find sprinkle of info here and there but no overall explanation of how this ajax framework works. Is there a good explanation out there?

dev.e.loper
  • 34,180
  • 71
  • 151
  • 237
  • so far examining the samples I've found css class: input-validation-error and input-validation-valid, still I feel like I'm missing a good reference. Nice question. – BigMike Nov 03 '11 at 15:43
  • 2
    I know that source is best documentation. I could go through their js files to figure out what is happening and I'd be a better man for it but I thought I'd ask first and see if that work is already done for me. – dev.e.loper Nov 03 '11 at 15:50

2 Answers2

1

The Ajax Helper methods render Html to your page.

The best way to see exactly what an Ajax Helper method adds is by viewing the source when it renders in your browser at runtime.

You can even see the unobtrusive stuff rendered in the source if you remove your reference to the jquery.unobtrusive-ajax.js.

You can also write your own Ajax (and Html) Helper methods in the form of Extension Methods.

PeteGO
  • 5,132
  • 2
  • 35
  • 64
0

MVC3 Ajax helpers simply add some css class names and data on the form element. You have to include jquery.unobtrusive-ajax.js in your project.

When the dom is ready, this script searches form elements with the above css class names. When the form is submitted, the script catch the event, serialize the form values, use $.ajax to call the target url, and can put the response into a given element id, or give it to your custom js method depending on the options you used.

input-validation-error and input-validation-valid classes are used for unobtrusive validation, which is not the same as unobtrusive ajax (they only share the word unobtrusive). It needs jquery.validate.unobtrusive.js and transform microsoft script validation into jquery validate validation. See http://rocketsquared.com/wiki/Plugins/Validation for details about jquery validate validation.

Softlion
  • 11,311
  • 10
  • 52
  • 78
  • with MVC 3 they switched to jQuery AJAX completely (MS Ajax is a long gone friend/fiend now) – BigMike Nov 16 '11 at 12:42
  • They do not. Default is to use MsAjax. You now have the choice. With previous versions you don't. MsAjax is undocumented in many ways. jQuery is. Choose yourself, but i prefer the jQuery fluid javascript to MsAjax monstruous but meaningfuls names. – Softlion Nov 17 '11 at 13:28