Skip to content

Instantly share code, notes, and snippets.

@infocynic
infocynic / knockout-3.0.0.aspnet-bindings.js
Last active September 22, 2015 18:45
Adds Knockout 3 bindings for rendering ASP.Net MVC input and validation markup for indexed primitive and complex types.
// Assigns an ASP.Net MVC-style name attribute to a form field that is part of a list.
// Used inside a foreach: binding.
// Example for an indexed primitive type (string, int, etc.) :
// <div data-bind="foreach: Items">
// <input type="text" data-bind="value: SomeValue, aspnetIndexedName: 'Items'" />
// </div>
//
// The above will name the input fields "Items[0]", "Items[1]", etc. For a complex type,
// a property can be specified in addition to the name:
// <div data-bind="foreach: Items">