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:
regContext.AddDataRoute<List<User>>("lyniconusers", "Lynicon/Users", new { controller = "User", action = "List", view = "LyniconListDetail", listView = "UserList" }); ... EditorRedirect.Instance.Register(typeof(List<User>), new ListEditorRedirect(new List<string> { "UserName", "Email", "Created", "Modified", "Roles" }));
This is how the route for the user page is registered.
For list editing, we need editing requests to go to a list editor. The EditorRedirect.Instance.Register() call does this, this technique is described further in Editors.
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 set by the ListEditorRedirect in the RouteData.Values. The view for the overall list editor whose name is held in 'view' is automatically invoked to generate the list editor. Within this, the values for 'listView' and 'rowFields' are used to build the list editor.
The values can be set in different ways as follow (in preference order):
- view
- On the route via the default object (as in the above example ... view = "LyniconListDetail" ...)
- On the content class via ListEditorAttribute
- On the ListEditorRedirect by using the 'view' parameter in the constructor
- If none of the above are done, the default is "LyniconListDetail"
- listView
- On the route via the default object (as in the above example ... listView = "UserList" ...)
- If this is not done, the default is "ObjectList"
- rowFields
- On the route via the default object
- On the ListEditorRedirect by using the 'listView' parameter in the constructor (as in the above example)
- If this is not done, the default is all the persisted properties of the content type except any property called "Id"
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.