jQuery.serializeArray() works also outside a form

 

Quote from jQuery docs: "Note that serializeArray() only works on form elements, using this method on another element will not work."

(http://docs.jquery.com/Ajax/serializeArray)

 

However, this is wrong, at least in 1.4.2 because I’m using the function to send some params to a controller this way:

<input type="hidden" id="LicenseId" name="LicenseId" value="" class="markerDTO" />
<input type="hidden" id="marker_Color" name="marker.Color" value="" class="markerDTO" />
<input type="hidden" id="marker_Id" name="marker.Id" value="" class="markerDTO" />

The 3 fields are not included in any <form></form>

var oo = $(‘.markerDTO‘).serializeArray();

jQuery.ajax({
            url: ‘-my-url-‘,
            dataType: ‘json’,
            data: jQuery.param(oo),
            complete: function()
            {
                var licenseId = $("#LicenseId").val();
                var color = $("#marker_Color").val();

                $(‘div.marker-color[license-id=’ + licenseId + ‘]’).css(‘background-color’, color );

                // unblock when remote call returns
                jQuery.unblockUI();
            }
        });

 

Also it works with just one input:

var oo = $(‘#LicenseId’).serializeArray();

Advertisements

NVelocity over Spark

Ever since I started to build web applications using Castle Monorail, I used NVelocity as view engine.

I know many think is not powerful enough and that there are view engines better than NV. Still, for our projects, NV was just enough.

For Storingen project I decided to user Spark v1.0, a new view engine built initially for MS-MVC. Now that the project was launched to production, I though I’d share some thoughts on Spark vs. NVelocity.

1. For a view engine having the slogan “less is more”, Spark is way too verbose.

Compare this:

Spark:

<test if="PropertyBag['actionResult'] !=null">
    <p style="color:red"> ${PropertyBag['actionResult']}</p>
</test>

NV:

#if ($actionResult)
    <p style="color:ff0000"> $actionResult</p>
#end

2. Try to debug this:

Dynamic view compilation failed.

c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\my.project\f6ea7153\3708dd9104e947bd8207471079fe1268-1.cs(151,138):

error CS0103: The name ‘pipeLocations’ does not exist in the current context

True, Spark too throws the error + code line in the face in some situations, but I didn’t figured out which ones.

3. Spark was built with MS MVC in mind thus its integration with Monorail is not entirely functional.

For example, ${Form.DisableValidation()} does not work.

4. Another annoying thing is that I have to declare the <viewdata Cities=”List<Storingen.Model.Cities>/> although I have already added the Cities in the PropertyBag in the controller.

The only advantage with Spark is that I can use C# code directly in views while in NV I had to build some helpers.

In Spark though, I have to declare the variables that I need in the view: <var Format=new FormatHelper()/>.

In the end, I have to admit that switching from NV to Spark was quite a shock for me…

P.S. for the next projects I’m heading to AspView, then for Brail… or the other way around..