Is there a good explanation on what ASP.NET MVC3 is doing with its ajax helpers and rendering unobtrusive javascript?
Asked Answered
K

2

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?

Kirin answered 3/11, 2011 at 15:29 Comment(2)
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.Firewood
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.Kirin
C
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.

Correspond answered 18/11, 2011 at 22:55 Comment(0)
H
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.

Hatching answered 15/11, 2011 at 15:0 Comment(2)
with MVC 3 they switched to jQuery AJAX completely (MS Ajax is a long gone friend/fiend now)Firewood
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.Hatching

© 2022 - 2024 — McMap. All rights reserved.