---
title: Retrieving content on MVC sites
related:
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/generating-classes-for-kentico-objects.md
  - https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/retrieving-content-on-mvc-sites/working-with-page-attachments-in-mvc-applications.md
  - https://docs.kentico.com/k11/custom-development/working-with-pages-in-the-api.md
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

The following section provides examples on how you can retrieve Kentico data in MVC applications. You can work with the following Kentico objects:

- Pages
- Page attachments
- Form records
- Custom table items
- Custom module classes
- Media library files

To retrieve content from page, form, custom table, and custom module class objects, we recommend [generating classes](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/generating-classes-for-kentico-objects.md) for these objects and using the generated code in your application.

## Retrieving pages

To work with pages, you need to use [generated](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/generating-classes-for-kentico-objects.md) strongly typed classes for page types.

The following example uses a generated code for the _DancingGoat.Article_ page type. You can use the generated providers when retrieving individual pages.

```csharp

// Gets the specified articles using the generated provider
IEnumerable<Article> articles = ArticleProvider.GetArticles()
    .OnSite("MySite")
    .Culture("en-US")
    .Path("/Articles/", PathTypeEnum.Children);

// Gets the published version of a single article using the generated provider
Article article = ArticleProvider.GetArticle(nodeGuid, "en-US", "MySite");

```

By default, the generated code returns published version of pages. If you need to retrieve the latest edited version of a page, use the following approach:

```csharp

// Gets the latest version of a single article using the generated provider
Article article = ArticleProvider.GetArticle(nodeGuid, "en-US", "MySite")
    .LatestVersion()
    .Published(false);

```

To filter the retrieved pages, you can use any of the query parameters for a single page type listed in [Working with pages in the API](https://docs.kentico.com/k11/custom-development/working-with-pages-in-the-api.md).

### Working with retrieved page data

You can access the data of a retrieved page through the properties of the object. The following types of page data are available:

- Page form data – the data that is editable on a page's _Form_ tab.
- General page data – properties available for all pages (via the _TreeNode_ class). For example identifiers, values indicating the position in the content tree, etc.
- Metadata – data like the _page title_ and _page keywords._

#### Accessing page form data

The fields available on a page's Form tab are specific to its Page type. You can see the fields that each page type uses:

- In _Pages types (application) -> edit page type -> Fields_ tab
- In the corresponding _\__ database table

We recommend accessing specific fields of a page type via the _Fields_ property:

```csharp

// Retrieves a specific page
News news = NewsProvider.GetNews(nodeGuid, "en-US", "MySite");

// Accesses the 'Title' field
string title = news.Fields.Title;

// Accesses the 'Text' field
string text = news.Fields.Text;

```

> **Note:** **Resolving HTML tags and relative URLs**
>
> Fields which are populated by the **Rich text editor** form control may contain HTML tags and relative links. To ensure that the content is displayed correctly, use one of the following methods:
>
> - _Html.Raw_ method disables the HTML encoding for the values.
> - _Html.Kentico().ResolveUrls_ extension method disables the HTML encoding for the values and resolves relative URLs to their absolute form.
>
> ```csharp
>
> @Html.Raw(Model.<Rich text field content>)
> @Html.Kentico().ResolveUrls(Model.<Rich text field content>)
>
> ```

#### Retrieving page attachments

For information on retrieving page attachments, see [Working with page attachments in MVC applications](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/retrieving-content-on-mvc-sites/working-with-page-attachments-in-mvc-applications.md).

## Retrieving form data

The following example requires the classes [generated](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/generating-classes-for-kentico-objects.md) for the _ContactUs_ form included in the solution.

```csharp

// Gets all form items
IEnumerable<ContactUsItem> items = BizFormItemProvider.GetItems<ContactUsItem>();

// Gets a single form item for a given form item ID
ContactUsItem item = BizFormItemProvider.GetItem<ContactUsItem>(1);

```

## Retrieving custom table data

The following example requires the classes [generated](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/generating-classes-for-kentico-objects.md) for the _SampleTable_  custom table included in the solution.

```csharp

// 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 class data

The following example requires the classes generated for the _Office_ custom module class included in the solution.

See the [Creating custom modules](https://docs.kentico.com/k11/custom-development/creating-custom-modules.md) page for information on creating custom module classes and generating code to work with them in your application.

```csharp

// 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);

```

## Retrieving media library data

For information on retrieving media files from media libraries, see [Working with media libraries on MVC sites](https://docs.kentico.com/k11/developing-websites/developing-sites-using-asp-net-mvc/developing-mvc-applications/retrieving-content-on-mvc-sites/working-with-media-libraries-on-mvc-sites.md).
