Tuesday, March 27, 2012

Preserve Telerik MVC Grid Checkboxes When Paging

var selectedIds = [];

$(document).ready(function () {
//wire up checkboxes.
$('#YOUR_GRID_ID :checkbox').live('change', function (e) {
var $check = $(this);
//console.log($check);
if ($check.is(':checked')) {
//add id to selectedIds.
selectedIds.push($check.val());
}
else {
//remove id from selectedIds.
selectedIds = $.grep(selectedIds, function (item, index) {
return item != $check.val();
});
}
});
});

function onDataBound(e) {
//restore selected checkboxes.
$('#YOUR_GRID_ID :checkbox').each(function () {
//set checked based on if current checkbox's value is in selectedIds.
$(this).attr('checked', jQuery.inArray($(this).val(), selectedIds) > -1);
});
}

Source

Monday, February 27, 2012

LINQ to Object - Distinct()

Have a read through K. Scott Allen's excellent post here:

And Equality for All ... Anonymous Types

The short answer:

Turns out the C# compiler overrides Equals and GetHashCode for anonymous types. The implementation of the two overridden methods uses all the public properties on the type to compute an object's hash code and test for equality. If two objects of the same anonymous type have all the same values for their properties – the objects are equal.

So it's totally safe to use the Distinct() method on a query that returns anonymous types.

Monday, May 23, 2011

MVC Theme View Engine

http://cgeers.wordpress.com/2010/02/25/asp-net-mvc-themed-view-engine/#viewengine