Routing for lists of data

DataRoute has a special facility for handling lists of content.  To use this to work with a content type SomeContent, add a DataRoute of type List<SomeContent>. The DataRoute will then call the GetList method of Collator to retrieve the relevant data.  GetList will analyse the query string arguments of the current url using the OData standard, filtering and/or paging the list of data as appropriate.

An example of this is as follows:

routes.MapDataRoute<List<TestContent>>("TestList", "test-list", new { controller = "User", action = "List" });

When building a list editor, Lynicon determines 3 values:

  • view: the overall template for the list editor
  • listView: the template for the list of items within the list editor
  • rowFields: a list of strings, each one being the name of a property shown in a column of the list in the list editor

These values are read from the RouteData.DataTokens collection, which you can set on the route like this:

routes.MapDataRoute<List<TestContent>>("test-list", "test-list",
	new { controller = "Test", action = "List" },
	null,
	new { view = "LyniconListDetail", listView = "ObjectList", rowFields = "Title, TestText" });

This example shows how you would do that. This example sets view and listView to their normal defaults. The rowFields parameter will default to the list of all value-typed properties on the content type.

To see how the views can be constructed, have a look at the views at /Areas/Lynicon/Views/ListEditor/LyniconListDetail.cshtml and /Areas/Lynicon/Views/Shared/EditorTemplates/UserList.cshtml.