Thursday, June 21, 2012

Custom Telerik MVC Grid Ajax Binding

Here's a code block demonstrating the manual sort/filter/paging of an ajax-bound Telerik MVC Grid request--it's handy for hook-ins of various flavors.

public ActionResult CustomBindingResult(IEnumerable items)
{
    int page = int.Parse(Request["page"]);
    int size = int.Parse(Request["size"]);
    string orderBy = Request["orderBy"];
    string groupBy = Request["groupBy"];
    string filter = Request["filter"];

    var list = items.ToList();
    var filtered = (IEnumerable)list.AsQueryable().ToGridModel(1, int.MaxValue, null, null, filter).Data;
    var results = (IEnumerable)filtered.AsQueryable().ToGridModel(page, size, orderBy, groupBy, null).Data;
    var data = results.Select(result => Activator.CreateInstance(typeof(TDestination), result));
    var model = new GridModel { Data = data, Total = filtered.Count() };
    return View(model);
}

Will need the Telerik.Web.Mvc.Extensions namespace.

Wednesday, June 13, 2012

Storing State in the Url Hash

It can be done. We have the technology.
function settingsToStorage(settings) {
    var s = [];
    $.each(settings, function (key, value) {
        s.push(key + "=" + encodeURIComponent(value));
    })
    return s.join("&");
}

function settingsFromStorage(storage) {
    var settings = {};
    storage.replace(/[#&]+([^=&]+)=([^&]*)/gi, function (m, key, value) { settings[key] = decodeURIComponent(value); });
    return settings;
}

Thursday, June 7, 2012

HTTP Error 403.14 in IIS 7.5

I get this error the first time I try to set up IIS for local development on a new 64-bit Windows install.
Turns out, ASP.NET 4 isn't yet properly registered with IIS. To do so, run the following from an administrator-level command prompt:

%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe -ir

Do the same for a 32-bit Windows install except with s/Framework64/Framework/.