Retrieving content in MVC applications

The following section describes how to retrieve Kentico data in MVC applications. You can work with the following system objects:

Retrieving form, custom table, and custom module data

Forms, custom tables, and custom modules all use the same process for retrieving stored entries from their corresponding database tables. To retrieve content from these objects, include their generated classes into your solution and use their API in the code in your application.

Retrieving form data

When retrieving forms data, use BizFormItemProvider and the generated <FormCodeName>Item class. BizFormItemProvider supplies two methods to facilitate form data retrieval:

  • GetItem<TType> returns a record of the specified type and ID.
  • GetItems<TType> – returns all records of the specified type using the ObjectQuery API.

The following example demonstrates how to retrieve individual submissions from a 'Contact Us' form. The code uses the ContactUsItem class generated via the form's Code tab to work with individual submitted entries.

// Gets all form items of the given type
IEnumerable<ContactUsItem> items = BizFormItemProvider.GetItems<ContactUsItem>();
 
// Gets a single form item with the given type and ID
ContactUsItem item = BizFormItemProvider.GetItem<ContactUsItem>(1);

Retrieving custom table data

When retrieving custom table data, use CustomTableItemProvider and the generated <CustomTableCodeName>Item class. CustomTableItemProvider provides two methods to facilitate form data retrieval:

  • GetItem<TType>  returns a record of the specified type and ID.
  • GetItems<TType> – returns all records of the specified type using the ObjectQuery API.

The following example demonstrates how to retrieve individual records from a custom table called 'Sample table'. The code uses the SampleTableItem class generated via the custom table's Code tab to work with individual submitted entries.

// Gets all custom table items
IEnumerable<SampleTableItem> items = CustomTableItemProvider.GetItems<SampleTableItem>();

// Gets a single custom table item for a given custom table item ID
SampleTableItem item = CustomTableItemProvider.GetItem<SampleTableItem>(1);

Retrieving custom module data

To retrieve data from custom module classes, generate their corresponding <ModuleCodeName>InfoProvider and <ModuleCodeName>Info object classes.

See the Creating custom modules page for information on creating custom module classes and generating classes to work with them in your application.

The following example shows how to work with items from a sample Office module.

// Gets all custom module class items
IEnumerable<OfficeInfo> items = OfficeInfoProvider.GetOffices();

// Gets a single custom module class item for a given class ID
OfficeInfo item = OfficeInfoProvider.GetOfficeInfo(1);

Was this page helpful?